Skip to content

Dependency Injection BoilerPlate

Dependency Injection with .NET inbuilt Dependency Injection framework

public void ConfigureServices(IServiceCollection services)
{
    ConfigureDependencyServices.getDependencies(services);
}

public static void getDependencies(IServiceCollection services)
{
    services.AddScoped<interface1, concreate1>();
    services.AddSingleton<interface2, concreate2>();
    services.AddTransient<interface3, concreate3>();

} 

    public class myController : ControllerBase
    {
        private readonly interface1 _concreate1;
        public myController(interface1 concreate1)
        {
            _concreate1 = concreate1;
        }

        //use user _concreate1 class
    }

Published inUncategorised

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *