I am using Autofac and I would like to isolate the main application from all the dependencies I register in the Autofac container.
This is a possible scenario:
I have a solution containing 4 projects. ProjectA is main application, a C# console program, containing the usual static class Program which I renamed to ClassA. ProjectB contains only ClassB and projectC contains ClassC. Both ClassB and ClassC are behind their interfaces, IClassB and IClassC, which are placed at projectD. ClassA calls a method of ClassB through IClassB. ClassB calls a method of ClassC through IClassC.
Inside ClassA I build the Autofac container and register the assemblies from projects B and C:
static class ClassA
{
static void Main()
{
var builder = new ContainerBuilder();
builder.RegisterType<ClassB>().As<IClassB>();
builder.RegisterType<ClassC>().As<IClassC>();
IContainer container = builder.Build();
}
}
At this point ProjectA has references to all other projects, even if alternatively register the dependencies using app.config based Autofac configuration.
Is there any way I make ProjectA to depend only on ProjectD where the interfaces are placed instead of depending on all projects?