public void ResolveMultipelWithScope() { var builder = new IocBuilder(); builder.RegisterSingleton <IA, A>(); builder.Register <IB, B>(); builder.Register <IC, C>(); builder.Register <ID, D>(); builder.Register <ID, D>(); builder.RegisterPerScope <ID, D>(); builder.Register <IF, F>(); var container = builder.Build(); IEnumerable <ID> d1; using (var scope = container.Scope) { d1 = scope.Resolve <IEnumerable <ID> >(); var d2 = scope.Resolve <IEnumerable <ID> >(); //Assert.AreNotEqual(d1.FirstOrDefault().GetHashCode(), d2.LastOrDefault().GetHashCode()); Assert.AreEqual(d1.LastOrDefault(), d2.LastOrDefault()); } var d3 = container.Resolve <IEnumerable <ID> >(); Assert.AreNotEqual(d1.FirstOrDefault(), d3.LastOrDefault()); Assert.AreNotEqual(d1.LastOrDefault(), d3.LastOrDefault()); }
public void ResolveMultipleWithSingletonAndMatch() { var builder = new IocBuilder(); builder.RegisterSingleton <IA, A>().Match <A>(); builder.Register <IB, B>(); builder.Register <IC, C>(); builder.Register <ID, D>(); builder.Register <ID, D>(); builder.RegisterSingleton <ID, D>().Match <D>(); builder.Register <IF, F>(); var container = builder.Build(); var f1 = container.Resolve <IF>(); var f2 = container.Resolve <IF>(); var a = container.Resolve <A>(); var d = container.Resolve <D>(); Assert.AreNotEqual(f1, f2); Assert.AreNotEqual(f1.Ds.FirstOrDefault().B, f2.Ds.FirstOrDefault().B); Assert.AreEqual(f1.Ds.FirstOrDefault().A, f2.Ds.FirstOrDefault().A); CollectionAssert.AreEqual(f1.Ds.Select(c => c.A).ToArray(), f2.Ds.Select(c => c.A).ToArray()); Assert.AreEqual(f1.Ds.FirstOrDefault().A, a); Assert.AreEqual(f1.Ds.LastOrDefault(), d); }
public void MissingRegistrationThrowsExceptionOnContainerBuild() { var builder = new IocBuilder(); builder.Register <IA, A>(); builder.Register <IC, C>(); builder.Register <ID, D>(); var container = builder.Build(); }
private static void RegisterDependencies(IocBuilder builder) { builder.Register <IRouteHandler>().Concrete <RouteHandler>(); builder.Register <IConfigManager>().Concrete <ConfigManager>().AsSingleton(); builder.Register <IConfigLoader>().Concrete <ConfigLoader>(); builder.Register <IFileSystemProvider>().Concrete <FileSystemProvider>(); builder.Register <IJsonReader>().Concrete <JsonReader>(); }
public void ResolveMultipleOfSameType() { var builder = new IocBuilder(); builder.Register <IA, A>(); builder.Register <IA, A>(); var container = builder.Build(); var a = container.Resolve <IEnumerable <IA> >().ToArray(); Assert.AreEqual(2, a.Count()); Assert.AreNotEqual(a[0], a[1]); }
public void AdvancedResolve() { var builder = new IocBuilder(); builder.Register <IA, A>(); builder.Register <IB, B>(); builder.Register <IC, C>(); var container = builder.Build(); var a = container.Resolve <IC>(); var b = container.Resolve <IC>(); Assert.AreNotEqual(a, b); }
public void ResolveLambda() { var builder = new IocBuilder(); builder.Register <IA, A>(); builder.Register <IC>(c => new C(c.Resolve <IA>(), c.Resolve <IB>())); builder.Register <IB, B>(); var container = builder.Build(); var ic = container.Resolve <IC>(); var id = container.Resolve <IC>(); Assert.AreNotEqual(ic, id); }
public void AdvancedResolveWithSingletonLambda() { var builder = new IocBuilder(); builder.Register <IA, A>(); builder.RegisterSingleton <IB>(c => new B()); builder.Register <IC, C>(); var container = builder.Build(); var a = container.Resolve <IC>(); var b = container.Resolve <IC>(); Assert.AreEqual(a.B, b.B); }
public void DeepObjectGraphWithWrongOrderAndSingletonResolve() { var builder = new IocBuilder(); builder.RegisterSingleton <ID, D>(); builder.Register <IA, A>(); builder.Register <IC, C>(); builder.Register <IB, B>(); var container = builder.Build(); var d1 = container.Resolve <ID>(); var d2 = container.Resolve <ID>(); Assert.AreEqual(d1, d2); }
public void DeepObjectGraphWithWrongOrderResolve() { var builder = new IocBuilder(); builder.Register <ID, D>(); builder.Register <IA, A>(); builder.Register <IC, C>(); builder.Register <IB, B>(); var container = builder.Build(); var d = container.Resolve <ID>(); var e = container.Resolve <ID>(); Assert.AreNotEqual(d, e); }
public override void Register(IocBuilder builder) { LogManager.Configuration = new XmlLoggingConfiguration("log.config"); builder .Register <IAppender, NLogAppender>() .RegisterPerScope <LoggingContext, LoggingContext>(); }
public void RegisterResolveKeyedFunc() { var builder = new IocBuilder(); builder.Register(c => new Func <string>(() => "hello")).IdentifiedAs("test"); var container = builder.Build(); var func = container.ResolveWithId <Func <string> >("test"); Assert.AreEqual("hello", func()); }
public void ResolveSelfRegistered() { var builder = new IocBuilder(); builder.Register <A, A>(); var container = builder.Build(); var a = container.Resolve <A>(); var b = container.Resolve <A>(); Assert.AreNotEqual(a, b); }
public void ResolveKeyed() { var builder = new IocBuilder(); builder.Register <G, G>(); builder.RegisterSingleton <IA, A>().IdentifiedAs("test"); var container = builder.Build(); var g = container.Resolve <G>(); var a = container.ResolveWithId <IA>("test"); Assert.AreEqual(g.A, a); }
public void SimpleResolve() { var builder = new IocBuilder(); builder.Register <IA, A>(); var container = builder.Build(); var a = container.Resolve <IA>(); var b = container.Resolve <IA>(); Assert.AreNotEqual(a, b); }
public void ScopeDisposesResolvedComponents() { var builder = new IocBuilder(); builder.Register <E, E>(); var container = builder.Build(); E a = null; using (var scope = container.Scope) { a = scope.Resolve <E>(); Assert.IsFalse(a.IsDisposed); } Assert.IsTrue(a.IsDisposed); }
public void ResolveMultipleOfSameTypeAsParameter() { var builder = new IocBuilder(); builder.Register <IA, A>(); builder.Register <IB, B>(); builder.Register <IC, C>(); builder.Register <ID, D>(); builder.Register <ID, D>(); builder.Register <IF, F>(); var container = builder.Build(); var f1 = container.Resolve <IF>(); }
public void ConfigureServices(IocBuilder builder) { builder.Register <TestServiceTwo>().As <ITestService>(); }
public override void Register(IocBuilder builder) { builder.Register <GameTimeline, GameTimeline>(); }