public void Setup() { var services = new ServiceCollection(); //services.AddTransient<IConfiguration>(provider => PopulateTestData.GetConfiguration(TestContext.CurrentContext.TestDirectory)); services.AddDbContext <ApplicationDbContext>(options => options.UseInMemoryDatabase()); services.AddTransient <IApplicationDBContext, ApplicationDbContext>(); //services.AddTransient<ISampleEntityService, SampleEntityService>(); //services.AddTransient<SampleTestEntitiesController>(); //var serviceProvider = services.BuildServiceProvider(); //_applicationDBContext = serviceProvider.GetService<IApplicationDBContext>(); //_SampleEntityService = serviceProvider.GetService<ISampleEntityService>(); //_SampleEntitiesController = serviceProvider.GetService<SampleTestEntitiesController>(); var container = new WindsorContainer(); var assemblyName = typeof(aspnetcoreoauth.Startup).Assembly.GetName().Name; container.Register(Component.For <IApplicationDBContext, ApplicationDbContext>().LifestyleTransient()); container .Register( Component.For <ISampleEntityService, SampleEntityService>() .LifestyleTransient()); container .Register( Classes.FromAssemblyNamed(assemblyName).Pick().If(p => p.Name.EndsWith("Controller")) .LifestyleTransient()); var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(container, services); _applicationDBContext = container.Resolve <IApplicationDBContext>(); _SampleEntitiesController = container.Resolve <SampleTestEntitiesController>(); _SampleEntityService = container.Resolve <ISampleEntityService>(); }
public SampleTestEntitiesController(ILogger <Controller> logger, ISampleEntityService service) { _logger = logger; _service = service; }
public ResolveControllerDependenciesMiddleware(ILogger <ResolveControllerDependenciesMiddleware> logger, ISampleEntityService service) { _logger = logger; _service = service; }