I want to provide a service like:
[ServiceContract]
interface IMyService<T>
{
[ServiceOperation]
void Foo(T item);
}
I can discover at runtime the Type of all arguments (using some attributes decorations) of my generic contract and using something like:
typeof(IMyService<>).MakeGenericType(typeof(Contact))
I can get the bounded generic type both for the contract and service implementation. Starting from a base configuration at runtime I can also add the endpoints to the host. Even more knowing all the data contracts I am interested in, I can add to the host a DataContractResolver for each of them
The challange is in hosting the service. At compile time I don't know the type argument, but I can find it at runtime. How can I extend ServiceHost or ServiceHostBase to inject in it the service type:
MyService<Contact>
when it is needed? ServiceHost will anyhow need it only at runtime...