Konwencje w autofacu

Część z nas jest mniej lub bardziej leniwa. Części może przeszkadzać taki zapis, a części nie.

public static void RegisterDependencies()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetCallingAssembly()).InstancePerLifetimeScope();
builder.RegisterType<RssChannelRepository>().As<IRssChannelRepository>();
builder.RegisterType<RssChannelsRepository>().As<IRssChannelsRepository>();
builder.RegisterType<RssChannelsSubscriptionsRepository>().As<IRssChannelsSubscriptionsRepository>();
builder.RegisterType<SocialLoginRepository>().As<ISocialLoginRepository>();
builder.RegisterType<UserRepository>().As<IUserRepository>();
builder.RegisterType<UpdateRepository>().As<IUpdateRepository>();
builder.RegisterType<RssEntriesRepository>().As<IRssEntriesRepository>();
builder.RegisterType<RssEntriesToReadRepository>().As<IRssEntriesToReadRepository>();
builder.RegisterType<ItanDatabaseContext>().InstancePerLifetimeScope();
builder.RegisterType<WebConfigReader>().As<IConfigurationReader>();
builder.RegisterType<SessionProvider>().As<ISessionProvider>();
builder.RegisterType<ApplicationLoginService>().As<ILoginService>();
builder.RegisterType<OpmlImporterService>().As<IOpmlImporterService>();
builder.RegisterType<UpdateService>().As<IUpdateService>();
builder.RegisterType<RssChannelService>().As<IRssChannelService>();
builder.RegisterType<RssChannelsService>().As<IRssChannelsService>();
builder.RegisterType<UpdateService>().As<IUpdateService>();
builder.RegisterType<RssSubscriptionService>().As<IRssSubscriptionService>();
builder.RegisterType<SessionProvider>().As<ISessionProvider>();
builder.RegisterType<UserAuthentication>().As<IUserAuthentication>();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}

Szczególnie część, gdzie powtarzają się różnego rodzaju serwisy i repozytoria (@7-@14) oraz (@21-@27). Co czynić, jak zrobić to samo za mniej? Konwencje i autoskanowanie assembly’ów. Jak? Poniżej prosta ściągawka: Continue reading