首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

autofac MVC3 求教解决方法

2012-07-30 
autofac MVC3 求教例如builder.RegisterTypeCorporationService().AsICorporationService().InstanceP

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

热点排行