public void Setup()
        {
            var unityServiceProvider = new UnityServiceProvider();

            ServiceProvider.Current   = unityServiceProvider;
            ServiceCollection.Current = unityServiceProvider;
        }
Ejemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            var services = new UnityServiceProvider();

            this.ConfigureServices(services);
            this.Configure(app, services);
        }
Ejemplo n.º 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var unityServiceProvider = new UnityServiceProvider();

            _serviceProvider = unityServiceProvider;

            var container = unityServiceProvider.UnityContainer;

            services.AddSingleton <IControllerActivator>(new UnityControllerActivator(container));
            services.AddSingleton(fac => container);

            var defaultProvider = services.BuildServiceProvider();

            container.AddExtension(new UnityFallbackProviderExtension(defaultProvider));

            //container.RegisterType<IMyUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager());

            //container.RegisterType<IMapper, Mapper>();
            //container.AddNewExtension<RepositoriesUnityExtension>();
            container.AddNewExtension <UnityExtension>();

            /*var eventLogFactory = new InjectionFactory((ctr, type, str) =>
             * {
             *  var appLog = new EventLog("Application");
             *  appLog.Source = "Web Api.";
             *
             *  return new CustomEventLog(appLog);
             * });*/

            //container.RegisterType<IEventLog>(new TransientLifetimeManager(), eventLogFactory);
        }
        public void UnityIsRegistered()
        {
            UnityContainer c = new UnityContainer();

            c.RegisterInstance <IServiceScopeFactory>(new UnityServiceScopeFactory(c));
            var sp = new UnityServiceProvider(c);

            c.RegisterInstance <IServiceProvider>(sp);
            c.RegisterSingleton <IFoo, Foo>();

            c.IsRegistered(typeof(IFoo)).Should().BeTrue();
        }
        public void UnityNotEnumerable()
        {
            UnityContainer c = new UnityContainer();

            c.RegisterInstance <IServiceScopeFactory>(new UnityServiceScopeFactory(c));
            var sp = new UnityServiceProvider(c);

            c.RegisterInstance <IServiceProvider>(sp);
            c.RegisterSingleton <IFoo, Foo>();

            var service = sp.GetRequiredService <IFoo>();

            service.Should().NotBeNull();
        }
        public void UnityEnumerable()
        {
            UnityContainer c = new UnityContainer();

            c.RegisterInstance <IServiceScopeFactory>(new UnityServiceScopeFactory(c));
            var sp = new UnityServiceProvider(c);

            c.RegisterInstance <IServiceProvider>(sp);
            c.RegisterSingleton <IFoo, Foo>("a");
            c.RegisterSingleton <IFoo, Foo2>("b");


            var services = sp.GetRequiredService <IEnumerable <IFoo> >().ToArray();

            services.Length.Should().Be(2);
        }
        public void ModelFactoryTest()
        {
            UnityContainer c = new UnityContainer();

            c.RegisterInstance <IServiceScopeFactory>(new UnityServiceScopeFactory(c));
            var sp = new UnityServiceProvider(c);

            c.RegisterInstance <IServiceProvider>(sp);


            c.RegisterFactory <Foo>(uc => uc.Resolve <IModelFactory>().Create <Foo>(), FactoryLifetime.Singleton);

            IModelFactory m = new UiModelFactory(sp);

            c.RegisterInstance <IModelFactory>(m);
            var expected = c.Resolve <Foo>();
            var actual   = c.Resolve <Foo>();

            actual.Should().Be(expected);
        }
        public void Singleton()
        {
            UnityContainer c = new UnityContainer();

            c.RegisterInstance <IServiceScopeFactory>(new UnityServiceScopeFactory(c));
            var sp = new UnityServiceProvider(c);

            c.RegisterInstance <IServiceProvider>(sp);
            c.RegisterSingleton <IFoo, Foo>();

            IFoo expected = c.Resolve <IFoo>();
            IFoo actual   = null;

            using (var scope = sp.CreateScope())
            {
                actual = scope.ServiceProvider.GetService <IFoo>();
            }

            actual.Should().Be(expected);
        }
Ejemplo n.º 9
0
        public async Task ProjectionsShouldWorkWithEventStore()
        {
            var policy = Policy
                         .Handle <Exception>()
                         .WaitAndRetry(100, x => TimeSpan.FromMilliseconds(50));

            await Cleanup();

            var aggregateId = Guid.NewGuid();

            await AppendEvent(aggregateId);

            IProjectionSchemaRegister schema = new ProjectionSchemaRegister();

            schema.Discover(typeof(EventStoreIntegrationTests).Assembly);

            var connection = await Connect();

            UnityContainer uc = new UnityContainer();

            uc.RegisterSingleton <IRoomAvailabilityModel, RoomAvailabilityModel>();

            IServiceProvider serviceprovider = new UnityServiceProvider(uc);

            throw new NotImplementedException();
            //connection.ConfigureWithEventBus(schema.Events,serviceprovider.GetService<IEventHandlerDispatcher>(), Logger.None);

            var model = uc.Resolve <IRoomAvailabilityModel>();

            policy.Execute(() => model.Rooms.Should().HaveCount(1));

            await AppendEvent(Guid.NewGuid());

            Thread.Sleep(2000);
            policy.Execute(() => model.Rooms.Should().HaveCount(2));
        }
Ejemplo n.º 10
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();

            services.AddMvc()
            .AddJsonOptions
            (
                options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()
            );

            var unityServiceProvider = new UnityServiceProvider();

            var container = unityServiceProvider.UnityContainer;

            DependencyRegister.Register(container, "mongodb://localhost:27017", "Rotaract");

            services.AddSingleton <IControllerActivator>(new UnityControllerActivator(container));

            var defaultProvider = services.BuildServiceProvider();

            container.AddExtension(new UnityFallbackProviderExtension(defaultProvider));

            return(unityServiceProvider);
        }
Ejemplo n.º 11
0
 protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
 {
     var unityServiceProvider = new UnityServiceProvider();
 }