ServiceCollectionRegistrar.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Castle.MicroKernel.Registration;
  5. using Castle.Windsor.MsDependencyInjection;
  6. using Abp.Dependency;
  7. using YGNT.Exam.EntityFrameworkCore;
  8. using YGNT.Exam.Identity;
  9. namespace YGNT.Exam.Tests.DependencyInjection
  10. {
  11. public static class ServiceCollectionRegistrar
  12. {
  13. public static void Register(IIocManager iocManager)
  14. {
  15. var services = new ServiceCollection();
  16. IdentityRegistrar.Register(services);
  17. services.AddEntityFrameworkInMemoryDatabase();
  18. var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services);
  19. var builder = new DbContextOptionsBuilder<ExamDbContext>();
  20. builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);
  21. iocManager.IocContainer.Register(
  22. Component
  23. .For<DbContextOptions<ExamDbContext>>()
  24. .Instance(builder.Options)
  25. .LifestyleSingleton()
  26. );
  27. }
  28. }
  29. }