I have the following:
public interface ISubject { ... }
public class Subject<T> : ISubject { ... }
public class MyCode<T> {
...
pulic void MyMethod()
{
var item = container.Resolve<ISubject>(); //????? how do I pass in T
}
...
}
In this case how do i do the resolve.
Cheers Anthony
vdhant - That's not how containers are meant to be used.
You want to use
ISubject
, right?. Then if you passed T you're breaking your abstraction, because your caller must know thatISubject
, is actually a Subject, and more than that, its aSubject<T>
and that it requires a concrete T.No container will allow that, but it's a design problem, not tool problem.
One thing to fix your design, would be to make it explicit - change
ISubject
toISubject<T>
Then you could register open generic type
ISubject<>
and bind it to open generic typeSubject<>
.Then you'd be able to do
You didn't provide any context so I may be off the track with the answer, but one thing is for sure - you have a design problem.