By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
close

About C# Programming Language: features, and syntax and so on.

rss_feed Subscribe RSS

.NET Core is built in with dependency injection. Usually method ConfigureServices in Startup class is used to register services in the container.

The signature of the method looks like the following:

public void ConfigureServices(IServiceCollection services)
{

}

Sometimes it may be necessary to instantiate a service in this function. To do that, you can use the following method:

var sp = services.BuildServiceProvider();
var dbConfig = sp.GetService<IOptions<DatabaseConfig>>().Value;

In the above example, the BuildServiceProvider function is invoked to create a service provider object which then is used to get service.

info Last modified by Raymond at 2 years ago
info About author

info License/Terms

Please log in or register to comment. account_circle Log in person_add Register
comment Comments (0)
No comments yet.