1

I have a mapper that takes data from a repository project. I have a IMenueMapper interface that is passed into the homecontroller like this:

public HomeController(IMenueMapper menueMapper)
{
    _menueMapper = menueMapper;
}

but the menuemapper class itself use the IMenueMapperRepository, and this come from another project and is passed in via dll

public MenueMapper(IMenueItemsRepository menueItems)
{
    _menueItems = menueItems;
}

While I can easily resolve the IMenuemapper in the MVC project, using structuremap.mvc5, I can't resolve the repository. Is there a way of achieving the DI in this instance?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Jack M
  • 2,564
  • 4
  • 28
  • 49
  • 1
    Why don't you use `For ` also for the `IMenueItemsRepository`? Something like this `For(typeof(IMenueItemsRepository)).Use(typeof(....))`, where `...` refers to a concrete implementation of `IMenueItemsRepository`. – Christos Feb 12 '17 at 11:42
  • You need to register the abstraction (repository interface and implementation) in the composition root. – Nkosi Feb 12 '17 at 11:45
  • @Nkosi What do you mean by that? – Jack M Feb 12 '17 at 11:58
  • @JackM how was `IMenueMapper ` registered with structure map container? – Nkosi Feb 12 '17 at 11:59
  • in the DefaultRegistry I have scan.AssemblyContainingType(); – Jack M Feb 12 '17 at 12:01
  • @Christos: where Would I put that? I tried using ////For().Use(); this.For().Use(); in the defaultRegistry of the MVC project but I am getting an error that the IMenueItemsRepository is not bound – Jack M Feb 12 '17 at 12:03
  • 1
    Can you do the same scan for `MenueItemsRepository`? You already stated it is in another assembly – Nkosi Feb 12 '17 at 12:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/135494/discussion-between-jack-m-and-nkosi). – Jack M Feb 12 '17 at 12:07
  • @Nkosi: you are right, I needed to add the dependency in the MVC project I am not sure how to accept your answer though. Thanks very much. – Jack M Feb 12 '17 at 12:25
  • @JackM, I compiled comments into an answer – Nkosi Feb 12 '17 at 12:33

1 Answers1

1

You need to register the abstraction (repository interface and implementation) in the composition root.

You indicated that the IMenueMapper is registered via;

scan.AssemblyContainingType<MenueMapper>();

Since

but the MenueMapper class itself use the IMenueMapperRepository, and this come from another project and is passed in via dll

Then it should also be scanned as it belongs to another assembly

scan.AssemblyContainingType<MenueItemsRepository>();

Make sure that the project references the assembly in question

Nkosi
  • 235,767
  • 35
  • 427
  • 472