// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <IEmailSender, EmailSender>(); var authService = new AuthenticationServices(null, null); authService.InitializeContext(services, Configuration); services.AddScoped <IAuthentication, AuthenticationServices>(); //Add persistence service services.AddScoped <IPersistenceContext, PersistenceContext>(); var dataService = services.BuildServiceProvider().GetService <IPersistenceContext>(); dataService.InitializeContext(services, Configuration); //Add Business Layer services.AddScoped <IBusinessLayer, BusinessLogic>(s => new BusinessLogic(dataService)); services.AddMvc(); }