autofac MVC3 求教
例如
builder.RegisterType<CorporationService>().As<ICorporationService>().InstancePerDependency();
builder.RegisterType<UserService>().As<IUserService>().InstancePerLifetimeScope();
可以合并成一句
builder.RegisterAssemblyTypes(typeof(CorporationService).Assembly)
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces().InstancePerDependency();
builder.RegisterType<Repository<Corporation>>().As<IRepository<Corporation>>().InstancePerLifetimeScope();
builder.RegisterType<Repository<User>>().As<IRepository<User>>().InstancePerLifetimeScope();
…… 这些很多能合并成一句吗?
------解决方案--------------------
C# code
builder.RegisterGeneric(typeof(Repository<>))
.As(typeof(IRepository<>))
.InstancePerLifetimeScope();