예제 #1
0
 private static void RegisterCoreServices()
 {
     Ioc.RegisterSingle(TypeRegistration.For <SimpleSynchronousEventDispatcher, IEventDispatcher>(Lifetime.PerLifetimeScope));
     Ioc.RegisterAllTypesDerivedFrom(
         typeof(IEventHandler <>),
         implementationType => TypeRegistration.AsImplementedInterfaces(implementationType, Lifetime.PerLifetimeScope));
 }
예제 #2
0
        public static Global.Configuration EnablePersistence(this Global.Configuration configuration, Action <PersistenceConfiguration> persistenceSetup)
        {
            Global.Ioc.RegisterSingle(TypeRegistration.For <SimpleParameterlessCtorConverter, IConverter>(Lifetime.PerLifetimeScope));

            persistenceSetup(new PersistenceConfiguration(configuration));

            return(configuration);
        }
예제 #3
0
        public void ShouldThrow_When_ImplementationType_IsNotAClass()
        {
            Global.Ioc.Register(TypeRegistration.For <int, object>());

            var ex = Assert.Throws <InvalidOperationException>(() => _target.Resolve <object>());

            Assert.Contains("type is not a class", ex.Message);
        }
예제 #4
0
        public void ShouldThrow_When_ImplementationType_HasNoParameterlessCtor()
        {
            Global.Ioc.Register(TypeRegistration.For <ServiceWithoutParameterlessCtor, ITestService>());

            var ex = Assert.Throws <InvalidOperationException>(() => _target.Resolve <ITestService>());

            Assert.Contains("type has no parameterless ctor", ex.Message);
        }
예제 #5
0
        public void ShouldThrow_When_ImplementationType_IsAnAbstractClass()
        {
            Global.Ioc.Register(TypeRegistration.For <AbstractTestService, ITestService>());

            var ex = Assert.Throws <InvalidOperationException>(() => _target.Resolve <ITestService>());

            Assert.Contains("type is an abstract class", ex.Message);
        }
        public static PersistenceConfiguration UseSqlite(this PersistenceConfiguration configuration, string dbPath)
        {
            Global.Ioc.RegisterSingle(TypeRegistration.For <SqliteStorageAdapter, IStorageAdapter>(Lifetime.PerLifetimeScope));

            configuration.GlobalConfiguration.SetParameter(DbPathParameterName, dbPath);

            return(configuration);
        }
예제 #7
0
        public void ShouldThrow_When_MoreThanOne_RegistrationFound()
        {
            Global.Ioc.Register(TypeRegistration.For <TestService, ITestService>());
            Global.Ioc.Register(TypeRegistration.For <TestService2, ITestService>());

            var ex = Assert.Throws <InvalidOperationException>(() => _target.Resolve <ITestService>());

            Assert.Contains("more than one registration for this type found", ex.Message);
        }
예제 #8
0
        public void Should_CreateInstance_When_TypesRegisteredProperly()
        {
            Global.Ioc.Register(TypeRegistration.For <TestService, ITestService>());

            var service = _target.Resolve <ITestService>();

            Assert.NotNull(service);
            Assert.Equal(typeof(TestService), service.GetType());
        }
예제 #9
0
        public void Should_CreateSingletonInstance_When_SingletonLifetime_Configured()
        {
            Global.Ioc.Register(TypeRegistration.For <TestService, ITestService>(Lifetime.Singleton));

            var service1 = _target.Resolve <ITestService>();
            var service2 = _target.Resolve <ITestService>();

            Assert.NotNull(service1);
            Assert.NotNull(service2);
            Assert.Same(service1, service2);
        }
예제 #10
0
        public void Should_CreateMultipleInstances_When_ResolvingThrough_GenericEnumerable()
        {
            Global.Ioc.Register(TypeRegistration.For <TestService, ITestService>());
            Global.Ioc.Register(TypeRegistration.For <TestService2, ITestService>());

            var services = (_target.Resolve(typeof(IEnumerable <ITestService>)) as IEnumerable).OfType <ITestService>().ToList();

            Assert.NotEmpty(services);
            Assert.Equal(2, services.Count);

            Assert.Contains(services, x => x.GetType() == typeof(TestService));
            Assert.Contains(services, x => x.GetType() == typeof(TestService2));
        }
예제 #11
0
        public void Should_CreateMultipleInstances_When_TypesRegisteredProperly()
        {
            Global.Ioc.Register(TypeRegistration.For <TestService, ITestService>());
            Global.Ioc.Register(TypeRegistration.For <TestService2, ITestService>());

            var services = _target.ResolveMany <ITestService>().ToList();

            Assert.NotEmpty(services);
            Assert.Equal(2, services.Count);

            Assert.Contains(services, x => x.GetType() == typeof(TestService));
            Assert.Contains(services, x => x.GetType() == typeof(TestService2));
        }
예제 #12
0
        /// <summary>
        /// Enables very simple persistence based on the in-memory storage. It is good option for prototyping, MVPs. But it should not be used in any production
        /// ready functionality. Transactions are NOT supported in this storage.
        /// </summary>
        public PersistenceConfiguration UseInMemoryStorage()
        {
            Global.Ioc.RegisterSingle(TypeRegistration.For <InMemoryStorageAdapter, IStorageAdapter>(Lifetime.PerLifetimeScope));

            return(this);
        }