我移植一些旧的软件到.NET的核心2.0 ...依赖注入:在对.NET核心注入配置2.0
我想从一个基类在我的课DBActivityRepository注入一个连接字符串。 ..
如果我只是通过配置在创建基类
this._DBHandler = new DBHandler(configuration);
的或者是更好地做这种方式:
private DBHandler _DBHandler;
private string connectionString;
public DBActivityRepository(IConfiguration configuration) : base(configuration)
{
// **Do I need this?**
this._DBHandler = new DBHandler(configuration);
connectionString = this._DBHandler.GetConnectionString();
}
谢谢
https://www.codeproject.com/Articles/1204089/ASP-NET-Core-Dependency-Injection – Ramankingdom
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/依赖注入 – Ramankingdom