public IScopedDependencyResolver GetResolver() { var builder = new IoCContainerBuilder(); builder.AddResttpControllers(Assembly.GetExecutingAssembly()); builder.AddInstance(() => 3).For<int>(); builder.AddType<Object>().ForSelf().WithParameters(new Parameter("Labas", "labas")).SetSingleton(); builder.AddType<Object>().For<IList>().SetPerDependency(); builder.AddType<Object>().ForImplementedInterfaces().SetPerRequest(); builder.AddInstance(() => new Object()).For<Object>().SetSingleton(); builder.AddInstance(() => new object()).ForSelf().SetPerRequest(); builder.AddInstance(() => new object()).ForImplementedInterfaces().SetPerDependency(); return builder.Build(); }
public void Should_AddSetDelegateAndLookupType() { var builder = new IoCContainerBuilder(); var component = builder.AddInstance(() => 3).ForSelf(); Assert.IsNotNull(component.ComponentRegistration.CreateType); Assert.IsNotNull(component.ComponentRegistration.LookupTypes.First()); Assert.IsNotNull(component.ComponentRegistration.ResultFunc); Assert.IsTrue(component.ComponentRegistration.CreateType == typeof(int)); Assert.IsNotNull(component.ComponentRegistration.LookupTypes.First() == typeof(int)); Assert.IsTrue(component.ComponentRegistration.ResultFunc() is int); }
public void Should_ResolveAddInstance2() { var builder = new IoCContainerBuilder(); builder.AddInstance(() => new A()).ForSelf().SetSingleton(); var container = builder.Build(); var a = container.Resolve<A>(); Assert.IsNotNull(a); }
public void Should_ResolveAddInstance1() { var builder = new IoCContainerBuilder(); builder.AddInstance<IA1>(() => new A()).ForSelf().SetSingleton(); var container = builder.Build(); var ia1 = container.Resolve<IA1>(); var ia2 = container.Resolve<IA1>(); Assert.IsNotNull(ia1); Assert.IsNotNull(ia2); Assert.AreSame(ia1, ia2); }