How do I initialize an ILogger in a .NET 6 class library?

I’ve a class library, which is used by a console application. I now want to add a ILogger<T> via constructor injection in my class library. I came up with something like this: public class Class1 { private readonly ILogger<Class1> _logger; public Class1(ILogger<Class1> logger) { _logger = logger; } } Nevertheless I don’t know how I… Read More How do I initialize an ILogger in a .NET 6 class library?

Implement Repository and Db Context .Net Core Console Entity Framework with DI

I am creating a .NET Core 6 console application. I have a repository class StorageCompetitorRepository that implements an interface IStorageCompetitorRepository. The following is breaking and showing as null in Program.cs when I try to initialize: _storageCompetitorRepository = serviceProvider.GetService<StorageCompetitorRepository>(); The StorageCompetitorRepository class initializes the DbContext through the constructor. Program.cs: using Microsoft.Extensions.DependencyInjection; class Program { private static… Read More Implement Repository and Db Context .Net Core Console Entity Framework with DI

Core3.1 framework provided DI – how to get the instance of already registered type?

On .net core 3.1 Startup.cs Trying to get the instance of already registered type i.e. "IBusinessLogic" using "IServiceCollection", it is not working. How to get the instance of already registered type in .net core 3.1? public class Startup { public void ConfigureServices(IServiceCollection services) { container.Register<IBusinessLogic, BusinessLogic>(); container.AddSingleton<Func<string, string>> ((username, password) => new JWTCache(userId, password, container.GetInstance<IBusinessLogic>()));… Read More Core3.1 framework provided DI – how to get the instance of already registered type?