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>(); } }
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>(); } }
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>(); } }
public static void myFirstKonstrukt() { var b = new Konstruktor(); using (var s = b.beginScope()) { var bInstance = s.resolve <B>(); bInstance.A.printHelloWorld(); } }
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()); } }
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 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()); } }
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 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>(); } }
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()); } }
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); } }
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()); } }
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()); } }
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)); } }
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()); } }
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)); } }
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 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 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); } }
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)); } }
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 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()); } }
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); } }
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); } }
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); }
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); }
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); }
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); }
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()); }
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()); }