这是理念。
public interface IGeneralInterface { }
public interface IGenericInterface<T> : IGeneralInterface { }
public class GenericClass<T> : IGenericInterface<T> { }
public class SomeClient
{
Func<Type, IGeneralInterface> serviceFactory;
public SomeClient(Func<Type, IGeneralInterface> serviceFactory)
{
this.serviceFactory = serviceFactory;
}
public void DoSomething<T>()
{
var service = serviceFactory(typeof(T));
}
}
使用Autofac,如何将此服务工厂注入客户端,以便在调用client.DoSomething()时可以解决正确的服务?