Dotnetdi

From bibbleWiki
Revision as of 03:48, 10 August 2020 by Iwiseman (talk | contribs) (Created page with "=Registering a Service= ==Constructor Injection== With constructor Injection we define the list of required dependencies as parameters of the constructor for the class <syntax...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Registering a Service

Constructor Injection

With constructor Injection we define the list of required dependencies as parameters of the constructor for the class

class IainsController : Controller
{
    private IIainsWidget _iainsWidget;

    public IainsController(IIainsWidget iainsWidet)
    {
       _iainsWidget = iainsWidget;
    }
}

Registering a Service

In ASP Core the service must be registered with the IServiceCollection in the startup class configureServices.

public void ConfigureServices(IServiceCollection services)
{
    services.AddTransient<IIainsWidget, IainsWidget>();
}