public void AutoRegistration_MainComponentsSetUp() { var sw = new Stopwatch(); sw.Start(); var assembly = GetType().Assembly; var res = AutoRegistration.GetComponentMap(assembly, t => t == typeof(TestDependentObject), assembly, t => true); sw.Stop(); Assert.Equal( typeof(ProjectionQuery <object, Product, ProductDto>), res[typeof(IQuery <object, IEnumerable <ProductDto> >)]); Assert.Equal( typeof(PagedQuery <int, IdPaging <ProductDto>, Product, ProductDto>), res[typeof(IQuery <IdPaging <ProductDto>, IPagedEnumerable <ProductDto> >)]); Assert.Equal( typeof(GetByIdQuery <int, Product, ProductDto>), res[typeof(IQuery <int, ProductDto>)]); Assert.Equal( typeof(CreateOrUpdateHandler <int, ProductDto, Product>), res[typeof(ICommandHandler <ProductDto, int>)]); Assert.True(sw.ElapsedMilliseconds < 50); }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); // scan assemblies for types var currentAssembly = typeof(Startup).Assembly; var componentMap = AutoRegistration.GetComponentMap(currentAssembly , x => typeof(IController).IsAssignableFrom(x) , currentAssembly , x => x.IsInterface); // init conventions for automapper StaticAutoMapperWrapper.Init(cfg => { ConventionalProfile.Scan(currentAssembly); cfg.AddProfile <ConventionalProfile>(); }); // init IOC-container var container = new Container(); container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); var am = Lifestyle.Singleton.CreateRegistration(() => new StaticAutoMapperWrapper(), container); container.AddRegistration(typeof(IProjector), am); container.AddRegistration(typeof(IMapper), am); // Fake Context var reg = Lifestyle.Singleton.CreateRegistration(() => new FakeContext(new[] { new Product() { Category = new Category() { Rating = 100500 }, Id = 1, Name = "1 Product", Price = 100500, } , new Product() { Category = new Category(), Id = 2, Name = "2 Product", Price = 200500 } }), container); container.AddRegistration(typeof(ILinqProvider), reg); container.AddRegistration(typeof(IUnitOfWork), reg); foreach (var kv in componentMap) { container.Register(kv.Key, kv.Value, Lifestyle.Scoped); } // This is an extension method from the integration package. container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }