Dependency Injection

Table Of Contents

.NET Core

Setting up Dependency Injection is easy.

The RepositoryContainer class is the only class that needs to be injected and it implements the IRepositoryContainer interface.

The code below illustrates how to set up DI in the Startup.cs class in .NET Core.

// Replace SFDemo with the root namespace

// specified when you first generated the model

using SFDemo.Repository.Common;
using SFDemo.Repository.Container;
using SFDemo.Repository.Container.Interfaces;

// code omitted for brevity......

public void ConfigureServices(IServiceCollection services)
    // setup dependency injection as a singleton

    services.AddSingleton<IRepositoryContainer, RepositoryContainer>();
    // the rest of your code goes here..........