これは私のコードの一部で、助けが必要です:
// simple service locator
public class ServiceManager<TSvc> : IServiceManager<TSvc> where TSvc: class, IService
{
   private Dictionary<object, TSvc> services;
   public void RegisterService(TSvc service)
    {
        // omitted code here
        this.services.Add(service.GetType(), service); // dictionary
    }
    public T GetService<T>() where T : TSvc
    {
        T result = default(T);
        TSvc bufResult = null;
        if (this.services.TryGetValue(typeof(T), out bufResult))
            result = (T)bufResult;
        return result;
    }
    public TSvc GetService(Type serviceType)
    {
        TSvc result = null;
        this.services.TryGetValue(serviceType, out result);
        return result;
    }
}
次に、私のドメイン インターフェイス:
public interface IItem
{
   string Name { get; set; }
}
public interface IRepository<TModel> where TModel : IItem
{
    new IEnumerable<TModel> GetItems();
    void InsertItem(TModel item);
    void UpdateItem(TModel item);
    void DeleteItem(TModel item);
}
public interface IService<TModel> where TModel : IItem
{
    IRepository<TModel> Repository { get; }
}
次に、いくつかのドメイン クラス:
public class Book: IItem
{
    public string Name { get; set; }
}
public class BookRepo: IRepository<Book>
{
    new IEnumerable<Book> GetItems();
    void InsertItem(Book item);
    void UpdateItem(Book item);
    void DeleteItem(Book item);
}
public class BookService: IService<Book>
{
    IRepository<Book> IService<Book>.Repository { get { return this.Repository; } }
    BookRepo Repository { get; set;} 
}
ここで、「BookService」を使用して何かを行うことに興味がある場合は、次のようにサービス ロケーターから取得できます。
public void DoSomething()
{
    var bookService = serviceManager.GetService<BookService>();
    bookService.Repository.Insert(new Book()); 
}
しかし問題は、サービスのタイプが実行時にしか分からないことです (例: コンボボックスからの選択)。では、DoSomething メソッドはどのように見えるでしょうか?
public void DoSomething()
{
    var typeOfService = combobox.SelectedValue.GetType(); // cbx of services
    // ??? make use of serviceManager and typeOfService to get appropriate 'service'
    service.Repository.Insert(/*new IITem here*/);
}
また、どのように接続IServiceしますかIService<TModel>...解決策にたどり着く可能性もありますが、方法がわかりません。私のIServiceインターフェースは今のところ空白です...
お時間をいただき、誠にありがとうございます。不明な点があれば教えてください!ありがとうございました!
更新:あなたの回答に基づいて、リフレクションの部分が関与している可能性があると思います (NSGaga が指摘したようなもの) が、それでも、接続せずにIService、IService<TModel>私が望むものを達成することはできません。これを再設計する方法を誰が知っていますか?