.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 3 years ago copyright This page is subject to Site terms.

More from Kontext

Machine Learning with .NET in Jupyter Notebooks

local_offer plot local_offer machine-learning local_offer jupyter-notebook local_offer C# local_offer dotnet core

visibility 588
thumb_up 0
access_time 7 months ago

In this article, I'm going to show you how to install Jupyter in Windows and then install .NET kernel for Jupyter notebooks. It also shows a machine learning example using ML.NET. The target audience are .NET developers who want to expand their skills in data engineering and science domain...

open_in_new .NET Machine Learning

local_offer spark local_offer pyspark

visibility 4495
thumb_up 0
access_time 2 years ago

When creating Spark date frame using schemas, you may encounter errors about “field **: **Type can not accept object ** in type <class '*'>”. The actual error can vary, for instances, the following are some examples: field xxx: BooleanType can not accept object 100 in type ...

open_in_new Spark + PySpark

local_offer hive

visibility 1878
thumb_up 0
access_time 2 years ago

Since Hive 3.x, new authentication feature for HiveServer2 client is added. When starting HiveServer2 service (Hive version 3.0.0), you may encounter errors like: ‘HiveServer2 metastore.RetryingMetaStoreClient: RetryingMetaStoreClient trying reconnect as [username]  (auth:S...

open_in_new Hadoop

local_offer linux local_offer WSL local_offer ubuntu

visibility 7136
thumb_up 4
access_time 2 years ago

This page shows how to install Windows Subsystem for Linux (WSL) system on a non-system drive manually. Enable Windows Subsystem for Linux system feature Open PowerShell as Administrator and run the following command to enable WSL feature: Enable-WindowsOptionalFea...

open_in_new Tools

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward