如何在UnityConfig中获取HttpContext.Current?在应用程序启动时结果为null。我需要在依赖关系解析时获得应用程序的当前URL。这是我的代码
public static void RegisterTypes(IUnityContainer container)
{
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
// container.LoadConfiguration();
//this is null
var http = HttpContext.Current;
container
//add additional constructor to support the HostHelper of current set up
.RegisterType<IDataContextAsync, OEPDataContext>(new PerRequestLifetimeManager(), new InjectionConstructor(HostHelper.GetConfiguration()))
.RegisterType<IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager())
.RegisterType<IRepositoryAsync<Menu>, Repository<Menu>>()
.RegisterType<IMenuService, MenuService>();
// TODO: Register your types here
// container.RegisterType<IProductRepository, ProductRepository>();
}