Nikishkin Sergey Nikishkin Sergey - 1 year ago 159
C# Question

ASP.NET Core Dependency Injection

In my core solution I have 2 projects: app and library with model layer which contains pattern repository.

I ask DI in app realize my interface

services.AddTransient<IRepositrory, Repository>();

But! Repository constructor has parameter

public Repository(string connectionString)
_appDBContext = new AppDBContext(connectionString);

How correctly configure DI to create repository with specific string from
( app)?

Answer Source

There is an overload that accepts an implementation factory

services.AddTransient<IRepository>(isp => new Repository(conn));

You can get the connection string using

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download