0

Created a ASP.Net MVC3 application with DI container and using StructureMap. Everything works in controller method. But how can i do for a global.asax method?

Here I set the dependency resolver , Application_Start of global.ascx

    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;
    }
    }

In the this below line how can i do loosely coupling for a method call.

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

Note: TenantService class is expecting ITenantRepository

Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
  • 1
    I don't know very much StructureMap, but I think you could take the instance from your container. (since you've registred) – Felipe Oriani Dec 22 '12 at 12:29
  • @FelipeOriani Thanks, After reading http://stackoverflow.com/questions/5512040/ninject-ing-a-dependency-in-global-asax i found the way to get the instance from my DI container. It is working for me ! – Murali Murugesan Dec 22 '12 at 13:00

1 Answers1

1
DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));

You clearly have a reference to the StructureMap container (your variable container) so just call container.GetInstance<IMetaDataService>() etc.

Ben Foster
  • 34,340
  • 40
  • 176
  • 285