【发布时间】:2014-08-29 09:14:56
【问题描述】:
我想将 DI 与 MongoDB 的存储库类和接口一起使用,但它不起作用。我有这个错误:
MongoRepository`1 类型有多个长度为 2 的构造函数。无法消除歧义。
类构造函数:
public MongoRepository(string connectionString, string collectionName)
{
this.collection = Util<TKey>.GetCollectionFromConnectionString<T>(connectionString, collectionName);
}
public MongoRepository(MongoUrl url, string collectionName)
{
this.collection = Util<TKey>.GetCollectionFromUrl<T>(url, collectionName);
}
统一配置:
container.RegisterType(typeof(MongoRepository.IRepository<>), typeof(MongoRepository.MongoRepository<>));
如何在 Unity 中配置 DI?谢谢!!
【问题讨论】:
-
老实说,人们会为此大发雷霆,真正的解决方案是停止使用 Unity 并使用像 Autofac 这样的体面的 IoC 容器来处理任何你想扔给它的东西。 Unity 几乎在每一个障碍中都失败了。
标签: c# mongodb dependency-injection unity-container