I am building Autofac Container as below
_container = ConfigureContainer(new ContainerBuilder()).Build();
I have ConfigureContainer method to build/configure Autofac ContainerBuilder as below
private static ContainerBuilder ConfigureContainer(ContainerBuilder cb)
{
cb.RegisterModule(new QuartzAutofacFactoryModule());
cb.RegisterModule(new QuartzAutofacJobsModule(Assembly.GetExecutingAssembly()));
cb.Register(l => Logging.Logger.Instance()).As<ILogger>();
var reader = new ConfigurationSettingsReader();
cb.RegisterModule(reader);
// How do I convert following lines to Autofac Config?
cb.RegisterCollection<StandardTask>("IList<StandardTask>").As<IList<StandardTask>>();
cb.RegisterType<HealthMonitoringMessageDispatcherTask>().Named<StandardTask>("HealthMonitoringTask1").MemberOf("IList<StandardTask>");
cb.RegisterType<HealthMonitoringMessageDispatcherTask>().Named<StandardTask>("HealthMonitoringTask2").MemberOf("IList<StandardTask>");
cb.RegisterType<PurgeMessageDispatcherTask>().Named<StandardTask>("PurgeTask1");
cb.RegisterType<PurgeMessageDispatcherTask>().Named<StandardTask>("PurgeTask2");
return cb;
}
I have Autofac configuration section as below
<autofac>
<components>
<!--<component type="NAB.Custom.Logging.Logger, NAB.Custom.Logging" service="NAB.Logging.Core.ILogger, NAB.Logging" />-->
<component type="NAB.Windows.ServicesConsole.Services.SchedulerService, NAB.Windows.ServicesConsole" service="NAB.Windows.ServicesConsole.Services.Core.ITopshelfService, NAB.Windows.ServicesConsole" />
<component type="NAB.Windows.ServicesConsole.Jobs.HealthMonitoringMessageDispatcherJob, NAB.Windows.ServicesConsole" />
<component type="NAB.Windows.ServicesConsole.Jobs.PurgeMessageDispatcherJob, NAB.Windows.ServicesConsole" />
</components>
</autofac>
It resolves the configured component from the Custom Configuration Section correctly, but, I want to move following registrations from code to Custom Configuration Section as well, where I am unable to find proper solution for...
// How do I convert following lines to Autofac Config?
cb.RegisterCollection<StandardTask>("IList<StandardTask>").As<IList<StandardTask>>();
cb.RegisterType<HealthMonitoringMessageDispatcherTask>().Named<StandardTask>("HealthMonitoringTask1").MemberOf("IList<StandardTask>");
cb.RegisterType<HealthMonitoringMessageDispatcherTask>().Named<StandardTask>("HealthMonitoringTask2").MemberOf("IList<StandardTask>");
cb.RegisterType<PurgeMessageDispatcherTask>().Named<StandardTask>("PurgeTask1");
cb.RegisterType<PurgeMessageDispatcherTask>().Named<StandardTask>("PurgeTask2");
Any suggestions? Little code snippet will be very useful. Basically I am registering named collection and then injecting components to the collection which is constructor parameter of one of my registered objects.