I am working on a client interface (Silverlight) for a collection of a web method. And I try to avoid writing any kind of custom code for every web method. Therefore, I created ServiceCall<TResult>to handle each call, it TResultindicates the type of service return (I use XmlSerializerto create the returned instance). The client class provides a function that corresponds to each web method, and all that needs to be done is to create a new instance ServiceCall<TResult>, and TResultis indicated as the expected type of the returned method. And it works great.
I also use Ninject (dependency injector) to try to keep everything independent. Ninject supports open generics that are great for mine ServiceCall<TResult>.
But it also means that I entered a reference to the Ninject container. Which hides the dependency on ServiceCall<TResult>associated with the container. Therefore, I would like to introduce factory instead to create instances ServiceCall<TResult>. Which is not difficult, but I would like to make it a generic generic factory. Meaning I would like to have something like Factory<T<>>that would have a method public T<TU> Createinstance<TU>().
But I have no idea how to create a universal class with a type parameter, which itself is open genric.
Is this event possible in .Net? - Or do I need to create a specific ServiceCallFactory?
Edit:
I use interfaces for dependencies, but there is no need to mix them with this question, so I edited this without a question.
Timwi:
(DI) , . . . , .
( ). ( Ninject) factory .
public static class Factory<T>, , , T, , .
, " " ( pass in ServiceCall<MyResult>, MyResult)), , ( ), Ninject Get, .
; -, (Ninject), . , , Ninject. , , ServiceCall, Ninject, .
- Factory > , .
, , , , - ;)
, .