asp.net mvC语言 在Global.asax中的方法上使用依赖注入



创建ASP。Net mvc应用程序与DI容器和使用StructureMap。一切都在控制器方法中工作。但我怎么能做一个全球性的。asax方法?

这里我设置了global.ascx的依赖解析器Application_Start

    protected void Application_Start()
    {
    DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));
    LoadApplicationMetaData(?,?,?);
    }
      private void LoadApplicationMetaData(IMetaDataService metaService, ITenantService tenantService, ICacheStorage store)
    {
        store.Add("TenantMeta", tenantService.GetAllTenants());
    }
    public class TenantService : ITenantService
    {
    private readonly ITenantRepository TenantRepsitory;
    public TenantService(ITenantRepository _tenantRepository)
    {
        TenantRepsitory = _tenantRepository;
    }
    }

在下面这行中,我如何为方法调用做松耦合。

  **LoadApplicationMetaData(?,?,?); what should be passed** 

注意:TenantService类正在等待itenanrepository

DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));

你显然有一个对StructureMap容器(你的变量container)的引用,所以只调用container.GetInstance<IMetaDataService>()

最新更新