0

I currently have:

var container = new Container(x =>
{
    x.For<IService>().Use<Service>().Singleton();
}

This replaces all instances of new IService() with new Service();

I also have:

var T = typeof(IService);

How do I inject Service there?

MichaelAttard
  • 1,898
  • 2
  • 17
  • 26
  • Why would you want to do that? What are you trying to accomplish? – David Dec 26 '14 at 13:10
  • I am trying to initialize an attribute with dynamic parameters. [Log(type = typeof(IService))] – MichaelAttard Dec 26 '14 at 13:14
  • And why do you want to tightly couple that to an implementation instead of using an interface? Doesn't that defeat the purpose of using a dependency injection library in the first place? – David Dec 26 '14 at 13:15
  • I want to inject Service (implementation) where it says IService (interface). – MichaelAttard Dec 26 '14 at 13:18
  • Maybe we're both missing something? I don't see exactly what the problem is, StructureMap should be providing an instance of `Service` any time an instance of `IService` is requested from it. And throughout the rest of the domain the only type information needed is just `IService`. It's not clear to me what's broken here. – David Dec 26 '14 at 13:20
  • The problem is T becomes type IService instead of Service. – MichaelAttard Dec 26 '14 at 13:22
  • Right, but why is that a problem? Any instance of `Service` is of type `IService`. If that `typeof()` code is outside of the dependency implementation then it should never know about `Service`, only about `IService`. – David Dec 26 '14 at 13:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67717/discussion-between-user3233089-and-david). – MichaelAttard Dec 26 '14 at 13:23

0 Answers0