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

2
  • 1
    I don't know very much StructureMap, but I think you could take the instance from your container. (since you've registred) Commented Dec 22, 2012 at 12:29
  • @FelipeOriani Thanks, After reading stackoverflow.com/questions/5512040/… i found the way to get the instance from my DI container. It is working for me ! Commented Dec 22, 2012 at 13:00

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.