Exemple #1
0
 public void testIfInterface1IsRegistered()
 {
     using (var scope = b.beginScope())
     {
         scope.resolve <Interface1>();
     }
 }
        public static ILifetimeScope beginScope <RootT>(this Konstruktor konstruktor)
        {
            var scope = konstruktor.beginScope();

            scope.resolveRoot(typeof(RootT));
            return(scope);
        }
        public void testStringType()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve <RefersString>();
            }
        }
        public void testValueTypes()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve <RefersValueType>();
            }
        }
        public void ambiguous()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve<Ambiguous>();
            }
        }
        public void testValueTypes()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve<RefersValueType>();
            }
        }
        public void moreArguments()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve<MoreArguments>();
            }
        }
        public void ambiguous()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve <Ambiguous>();
            }
        }
Exemple #9
0
 public static void myFirstKonstrukt()
 {
     var b = new Konstruktor();
     using (var s = b.beginScope())
     {
         var bInstance = s.resolve<B>();
         bInstance.A.printHelloWorld();
     }
 }
        public void internalConstructor()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve <InternalConstructor>();
            }
        }
        public void moreArguments()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve <MoreArguments>();
            }
        }
        public void preferred()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve <Preferred>();
            }
        }
Exemple #13
0
        public void testStringType()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve<RefersString>();
            }
        }
        public void internalConstructor()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve<InternalConstructor>();
            }
        }
        public void preferred()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                s.resolve<Preferred>();
            }
        }
Exemple #16
0
        public static void myFirstKonstrukt()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                var bInstance = s.resolve <B>();
                bInstance.A.printHelloWorld();
            }
        }
Exemple #17
0
 public static void mapInterface()
 {
     var b = new Konstruktor();
     b.forInterface<IInterface>().instantiate<Implementation>();
     using (var s = b.beginScope())
     {
         var implementation = s.resolve<IInterface>();
         Assert.AreEqual(typeof(Implementation), implementation.GetType());
     }
 }
Exemple #18
0
 public static void explicitGenerator()
 {
     var b = new Konstruktor();
     b.registerGenerator<IGeneratorExample>(scope => new GeneratorExample());
     using (var s = b.beginScope())
     {
         var generated = s.resolve<IGeneratorExample>();
         Assert.AreEqual(typeof (GeneratorExample), generated.GetType());
     }
 }
Exemple #19
0
        public void testImplementationGenerator()
        {
            var builder = new Konstruktor();
            builder.registerGenerator(s => new Implementation());

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve<Implementation>();
                Assert.AreEqual(typeof(Implementation), dummy.GetType());
            }
        }
Exemple #20
0
        public void explicitZeroStore()
        {
            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                scope.store <A>(null);
                var br = scope.resolve <B>();
                Assert.AreEqual(null, br.A);
            }
        }
Exemple #21
0
        public void explicitZeroStore()
        {
            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                scope.store<A>(null);
                var br = scope.resolve<B>();
                Assert.AreEqual(null, br.A);
            }
        }
        public void preferredByBuilder()
        {
            var b = new Konstruktor();

            b.preferConstructor <PreferredByKonstruktor>(typeof(B));

            using (var s = b.beginScope())
            {
                s.resolve <PreferredByKonstruktor>();
            }
        }
Exemple #23
0
        public static void mapInterface()
        {
            var b = new Konstruktor();

            b.forInterface <IInterface>().instantiate <Implementation>();
            using (var s = b.beginScope())
            {
                var implementation = s.resolve <IInterface>();
                Assert.AreEqual(typeof(Implementation), implementation.GetType());
            }
        }
Exemple #24
0
        public static void explicitGenerator()
        {
            var b = new Konstruktor();

            b.registerGenerator <IGeneratorExample>(scope => new GeneratorExample());
            using (var s = b.beginScope())
            {
                var generated = s.resolve <IGeneratorExample>();
                Assert.AreEqual(typeof(GeneratorExample), generated.GetType());
            }
        }
        public void preferredByBuilder()
        {
            var b = new Konstruktor();

            b.preferConstructor<PreferredByKonstruktor>(typeof(B));

            using (var s = b.beginScope())
            {
                s.resolve<PreferredByKonstruktor>();
            }
        }
        public void testImplementationInstantiation()
        {
            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var dummy = scope.resolve<Dummy>();
                var dummy2 = scope.resolve<Dummy2>();

                Assert.AreEqual(dummy._d2, dummy2);
            }
        }
Exemple #27
0
        public void openGeneric()
        {
            var builder = new Konstruktor();

            builder.mapInterfaceToImplementation(typeof(IShared <>), typeof(Shared <>));

            using (var scope = builder.beginScope())
            {
                var shared = scope.resolve <IShared <int> >();
                Assert.AreEqual(typeof(Shared <int>), shared.GetType());
            }
        }
        public void testImplementationGenerator()
        {
            var builder = new Konstruktor();

            builder.registerGenerator(s => new Implementation());

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve <Implementation>();
                Assert.AreEqual(typeof(Implementation), dummy.GetType());
            }
        }
Exemple #29
0
        public void testExplicitGeneratorPrecedence()
        {
            var builder = new Konstruktor();
            builder.forInterface<IDummy>().generate(s => new Implementation());
            builder.forInterface<IDummy>().instantiate<Implementation2>();

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve<IDummy>();
                Assert.AreEqual(typeof(Implementation), dummy.GetType());
            }
        }
Exemple #30
0
        public static void explicitGeneratorPropertyInjection()
        {
            var b = new Konstruktor();
            b.registerGenerator(scope => new PropertyInjection {Generator = scope.resolve<GeneratorExample>()});

            using (var s = b.beginScope())
            {
                var generated = s.resolve<PropertyInjection>();
                Assert.AreEqual(typeof(PropertyInjection), generated.GetType());
                Assert.AreNotEqual(null, generated.Generator);
            }
        }
        public void testImplementationSecondaryUnregistered()
        {
            var builder = new Konstruktor();
            builder.forInterface<IDummy>().instantiate<Implementation>();

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve<IDummy>();
                var dummy2 = scope.resolve<ISecondary>();
                Assert.True(ReferenceEquals(dummy, dummy2));
            }
        }
Exemple #32
0
        public void testImplementationInstantiation()
        {
            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var dummy  = scope.resolve <Dummy>();
                var dummy2 = scope.resolve <Dummy2>();

                Assert.AreEqual(dummy._d2, dummy2);
            }
        }
        public void testImplementationSecondaryUnregistered()
        {
            var builder = new Konstruktor();

            builder.forInterface <IDummy>().instantiate <Implementation>();

            using (var scope = builder.beginScope())
            {
                var dummy  = scope.resolve <IDummy>();
                var dummy2 = scope.resolve <ISecondary>();
                Assert.True(ReferenceEquals(dummy, dummy2));
            }
        }
        public void testExplicitGeneratorPrecedence()
        {
            var builder = new Konstruktor();

            builder.forInterface <IDummy>().generate(s => new Implementation());
            builder.forInterface <IDummy>().instantiate <Implementation2>();

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve <IDummy>();
                Assert.AreEqual(typeof(Implementation), dummy.GetType());
            }
        }
Exemple #35
0
        public static void serverFunc()
        {
            var b = new Konstruktor();
            using (var s = b.beginScope())
            {
                var server = s.resolve<Server>();
                var client1 = server.createClient();
                var client2 = server.createClient();

                Assert.AreNotSame(client1, client2);
                Assert.AreSame(client1.Server, server);
                Assert.AreSame(client2.Server, server);
            }
        }
        public void testConcrete()
        {
            var builder = new Konstruktor();
            builder.forInterface<IDummy>().instantiate<Implementation>();

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve<IDummy>();
                Debug.Assert(dummy.GetType() == typeof(Implementation));

                var dummy2 = scope.resolve<IDummy>();
                Debug.Assert(ReferenceEquals(dummy, dummy2));
            }
        }
Exemple #37
0
        public static void serverFunc()
        {
            var b = new Konstruktor();

            using (var s = b.beginScope())
            {
                var server  = s.resolve <Server>();
                var client1 = server.createClient();
                var client2 = server.createClient();

                Assert.AreNotSame(client1, client2);
                Assert.AreSame(client1.Server, server);
                Assert.AreSame(client2.Server, server);
            }
        }
Exemple #38
0
        public void inOrderDispose()
        {
            _disposed.Clear();

            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                scope.resolve<A>();
            }

            Assert.AreEqual(2, _disposed.Count);
            Assert.AreEqual(typeof(A), _disposed[0].GetType());
            Assert.AreEqual(typeof(B), _disposed[1].GetType());
        }
Exemple #39
0
        public void openGenericGenerator()
        {
            var builder = new Konstruktor();

            builder.registerGeneratorsIn(GetType());

            using (var scope = builder.beginScope())
            {
                var shared = scope.resolve <IShared2 <Dummy> >();
                Assert.AreEqual(typeof(Shared2 <Dummy>), shared.GetType());

                var shared2 = scope.resolve <IShared2 <Dummy> >();
                Assert.AreEqual(shared, shared2);
            }
        }
Exemple #40
0
        public void inOrderDispose()
        {
            _disposed.Clear();

            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                scope.resolve <A>();
            }

            Assert.AreEqual(2, _disposed.Count);
            Assert.AreEqual(typeof(A), _disposed[0].GetType());
            Assert.AreEqual(typeof(B), _disposed[1].GetType());
        }
        public void testConcrete()
        {
            var builder = new Konstruktor();

            builder.forInterface <IDummy>().instantiate <Implementation>();

            using (var scope = builder.beginScope())
            {
                var dummy = scope.resolve <IDummy>();
                Debug.Assert(dummy.GetType() == typeof(Implementation));

                var dummy2 = scope.resolve <IDummy>();
                Debug.Assert(ReferenceEquals(dummy, dummy2));
            }
        }
Exemple #42
0
        public static void explicitGeneratorPropertyInjection()
        {
            var b = new Konstruktor();

            b.registerGenerator(scope => new PropertyInjection {
                Generator = scope.resolve <GeneratorExample>()
            });

            using (var s = b.beginScope())
            {
                var generated = s.resolve <PropertyInjection>();
                Assert.AreEqual(typeof(PropertyInjection), generated.GetType());
                Assert.AreNotEqual(null, generated.Generator);
            }
        }
Exemple #43
0
        public void openGenericAndExplicit()
        {
            var builder = new Konstruktor();

            builder.mapInterfaceToImplementation(typeof(IOG <>), typeof(OG <>));
            builder.mapInterfaceToImplementation(typeof(IOG <int>), typeof(ExplicitInt));

            using (var scope = builder.beginScope())
            {
                var fl = scope.resolve <IOG <float> >();
                var i  = scope.resolve <IOG <int> >();

                Assert.AreEqual(typeof(OG <float>), fl.GetType());
                Assert.AreEqual(typeof(ExplicitInt), i.GetType());
            }
        }
Exemple #44
0
        public void nestedScopeOwned()
        {
            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var referrer = scope.resolve <OwnedFactory>();

                Owned <NestedInstance> inst;

                using (inst = referrer.build())
                {
                }

                Assert.True(inst.Value.Disposed);
                Assert.True(inst.Value.Referred.Disposed);
            }
        }
Exemple #45
0
        public void nestedScopeOwned()
        {
            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var referrer = scope.resolve<OwnedFactory>();

                Owned<NestedInstance> inst;

                using (inst = referrer.build())
                {
                }

                Assert.True(inst.Value.Disposed);
                Assert.True(inst.Value.Referred.Disposed);
            }
        }
Exemple #46
0
        public void testFunc2()
        {
            _instanceDestructed = false;

            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var f = scope.resolve<Factory>();

                var p = new Param();
                var i = f._factory(p);
                Assert.AreEqual(i.P, p);
            }

            // sub-scopes do not dispose!, factory clients must handle that!

            Assert.AreEqual(false, _instanceDestructed);
        }
Exemple #47
0
        public void testFunc2()
        {
            _instanceDestructed = false;

            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var f = scope.resolve <Factory>();

                var p = new Param();
                var i = f._factory(p);
                Assert.AreEqual(i.P, p);
            }

            // sub-scopes do not dispose!, factory clients must handle that!

            Assert.AreEqual(false, _instanceDestructed);
        }
Exemple #48
0
        public void testFunc1()
        {
            _instancesDestructed = 0;

            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var f = scope.resolve<Factory>();
                var fi = scope.resolve<Instance>();

                var i = f._factory();

                Assert.AreNotSame(fi, i);
            }

            // sub-scopes do not dispose!, factory clients must handle that!

            Assert.AreEqual(1, _instancesDestructed);
        }
Exemple #49
0
        public void testFunc1()
        {
            _instancesDestructed = 0;

            var b = new Konstruktor();

            using (var scope = b.beginScope())
            {
                var f  = scope.resolve <Factory>();
                var fi = scope.resolve <Instance>();

                var i = f._factory();

                Assert.AreNotSame(fi, i);
            }

            // sub-scopes do not dispose!, factory clients must handle that!

            Assert.AreEqual(1, _instancesDestructed);
        }
Exemple #50
0
        public void interfaceDispose()
        {
            _disposed.Clear();

            var b = new Konstruktor();

            b.forInterface<IB>().instantiate<B>();

            using (var scope = b.beginScope())
            {
                // both should be the same object, but
                // dispose should be only called on A's instance (once).

                var b1 = scope.resolve<IB>();
                var b2 = scope.resolve<B>();

                Assert.AreSame(b1, b2);
            }

            Assert.AreEqual(1, _disposed.Count);
            Assert.AreEqual(typeof(B), _disposed[0].GetType());
        }
Exemple #51
0
        public void interfaceDispose()
        {
            _disposed.Clear();

            var b = new Konstruktor();

            b.forInterface <IB>().instantiate <B>();

            using (var scope = b.beginScope())
            {
                // both should be the same object, but
                // dispose should be only called on A's instance (once).

                var b1 = scope.resolve <IB>();
                var b2 = scope.resolve <B>();

                Assert.AreSame(b1, b2);
            }

            Assert.AreEqual(1, _disposed.Count);
            Assert.AreEqual(typeof(B), _disposed[0].GetType());
        }