Tuesday, April 10, 2018

constructor with parameter in .net core dependency injection

In .net core you register the dependency like

services.AddSingleton<IConfigsService, ConfigsService>();

If ConfigureService is taking parameter there is no way out of the box to pass the parameter value.

So in order to fix that, add the nuget parameter "Microsoft.Extensions.DependencyInjection"

services.AddTransient<IConfigsService>(c => new ConfigsService("Pass your data"));

And that should do it.

Thanks,