mongodb的通用存储库和通用上下文
我尝试实现一个通用存储库和通用上下文,以便与mongodb一起使用。 我遇到的问题是,我收到以下错误消息: 以下是我在startup类中的配置服务方法:mongodb的通用存储库和通用上下文,mongodb,generics,.net-core,mongorepository,Mongodb,Generics,.net Core,Mongorepository,我尝试实现一个通用存储库和通用上下文,以便与mongodb一起使用。 我遇到的问题是,我收到以下错误消息: 以下是我在startup类中的配置服务方法: public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.Configure<Settings>( options =>
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<Settings>(
options =>
{
options.ConnectionString = Configuration.GetSection("MongoDb:ConnectionString").Value;
options.Database = Configuration.GetSection("MongoDb:Database").Value;
});
services.AddTransient(typeof(IGenericContext<>), typeof(GenericContext<>));
services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>));
}
以及我的派生客户类:
public class Customer : BaseClass
{
[BsonElement]
public string CustomerName { get; set; }
}
你知道为什么我的通用存储库不能被实例化吗?这似乎是GenericContext的一个问题,但我不知道在哪里
谢谢我在我的通用存储库中发现了问题,我正在注入类而不是接口:
public GenericRepository(GenericContext<T> context)
公共通用存储库(通用上下文)
public class BaseClass
{
[BsonId]
public ObjectId Id { get; set; }
[BsonElement]
public string EntityId { get; set; }
}
public class Customer : BaseClass
{
[BsonElement]
public string CustomerName { get; set; }
}
public GenericRepository(GenericContext<T> context)