I am currently testing Autofac for our company.
We would like to have the following rules:
If the interface was implemented only once, add it automatically using builder.RegisterAssemblyTypes (see below).
Otherwise, we must make sure to manually write a rule that decides which implementation is the default implementation.
I have the following code:
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(Assembly
.Load("Lunch.Service")).As(t => t.GetInterfaces()[0]);
builder.RegisterType<ConsoleLoggerService>()
.As<ILoggerService>().SingleInstance();
builder.RegisterModule(new DestinationModule());
builder.RegisterType<TransportationService>()
.As<ITransportationService>().PropertiesAutowired();
Right now, it works, but it decides which first implementation will automatically create it. We would like to make this a manual process and give an error if we do not create a “rule” manually. Is it possible?
source
share