My container class looks like below:
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Core;
using Admin.Api.StuffApi.Commands;
using undefined.cmd;
using Microsoft.Extensions.Configuration;
//using Autofac.Util.Configuration.ConfigurationModule;
using Microsoft.Extensions.Configuration.Json;
namespace a_a
{
public static class GlobalContainer
{
public static IContainer Container { get; set; }
static GlobalContainer()
{
var builder = new ContainerBuilder();
var config = new ConfigurationBuilder();
config.AddJsonFile("IOCConfiguration.json");
var module = new ConfigurationModule(config.Build());
builder.RegisterModule(module);
Container = builder.Build();
}
}
}I have created a IOCConfiguration.Json file with autofac commands as below:{ //"defaultAssembly": "", "components": [ { "type": "undefined.cmd.StuffController" }, { "type": "Admin.Api.StuffApi.AppCode.Commands", "services": [{ "type": "Admin.Api.StuffApi.Commands.ICommands" }] } ] }Issue: When I run the Http request/API, I get the message as : The requested service 'Admin.Api.StuffApi.Commands.ICommands' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
I understand that my Json configuration (Registering the components ) are not being recognized, could anyone help me if I am missing anything with respect to configuration.
Thanks
http://autofac.readthedocs.io/en/latest/configuration/xml.html#default-assembly
It also looks like you may need to also look at the docs on integration with ASP.NET Core. None of what you have actually appears to integrate with ASP.NET Core at all.
http://autofac.readthedocs.io/en/latest/integration/aspnetcore.html
And don't forget to look at the Examples repo as well as unit tests for the configuration stuff to see real working examples of things.
https://github.com/autofac/Examples/tree/master/src/AspNetCoreExample
If this doesn't unblock you I'd recommend asking the question on StackOverflow and putting a link to the question from here. There's a lot bigger group of people (including most of the folks here) over on StackOverflow.