在Unity2,我会有这个工厂注册
iocContainer.AddNewExtension<StaticFactoryExtension>()
.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<string>("ApplicationPath", ioc => HttpContext.Current.Request.ApplicationPath);
iocContainer.AddNewExtension<StaticFactoryExtension>()
.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<string>("ApplicationUrl", ioc => ApplicationUrl());
iocContainer.AddNewExtension<StaticFactoryExtension>()
.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<string>("BaseUrl", ioc => BaseUrl());
iocContainer.AddNewExtension<StaticFactoryExtension>()
.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<RequestContext>(ioc => HttpContext.Current.Request.RequestContext);
iocContainer.AddNewExtension<StaticFactoryExtension>()
.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<ApplicationContext>(ioc => ApplicationContext.GetForRequest());
现在这已被弃用,只有Register才会到位,但我怎么能注册这些工厂呢?
答案 0 :(得分:0)
只是为了让人们知道,StaticFactory被InjectionFactory取代,所以
iocContainer.AddNewExtension<StaticFactoryExtension>()
.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<string>("ApplicationPath", ioc => HttpContext.Current.Request.ApplicationPath);
会变成
iocContainer
.RegisterType<string>("ApplicationPath", new InjectionFactory(ioc => HttpContext.Current.Request.ApplicationPath));