读书人

autofac MVC3 求教解决方法

发布时间: 2012-07-30 16:19:05 作者: rapoo

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(); 

读书人网 >asp.net

热点推荐