public void can_use_container_for_type_actions() { var container = TypeRegistry.Construct(x => x.AddContainer(new TestContainer())); var customer = container.GetInstance <ICustomer>(); customer.ShouldNotBeNull(); }
public void can_get_instace_from_non_generic_type() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <Customer, Customer>()); }); var customer = (Customer)container.GetInstance(typeof(Customer)); customer.Name.ShouldBeNull(); }
public void can_add_type_with_lifecycle() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <ICustomer, Customer>()); }); var customer = container.GetInstance <ICustomer>(); customer.Name.ShouldBeNull(); }
public void can_scan_assembly_and_register_selected_types() { var container = TypeRegistry.Construct(x => { x.TypeScanner(new[] { typeof(ICustomer).Assembly }, new[] { typeof(ICustomer) }); }); var customer = container.GetInstance <ICustomer>(); customer.ShouldNotBeNull(); }
public void can_get_type_with_ctor() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <IRepository, Repository>()); x.Add(new TypeAction <IProvider, StringProvider>()); }); var repo = container.GetInstance <IRepository>(); repo.Get().ShouldEqual("StringProvider"); }
public void can_set_properties_on_already_created_type() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <IProvider, StringProvider>()); }); var customer = new Customer(); container.SetProperties(customer); customer.Provider.ShouldNotBeNull(); customer.Provider.Get().ShouldNotBeNull(); }
public void can_add_and_get_closed_type() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction(typeof(IGenericProvider <>), typeof(GenericProvider <>))); x.Add(new TypeAction <ICustomerService, CustomerService>()); x.Add(new TypeAction <IRepository, Repository>()); x.Add(new TypeAction <IProvider, StringProvider>()); }); var service = container.GetInstance <ICustomerService>(); service.Get().Count().ShouldBeGreaterThan(2); service.Get2().ShouldNotBeNull(); }
public void can_get_type_with_generic_ctor() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <IGenericProvider <string>, GenericProvider <string> >()); x.Add(new TypeAction <ICustomerService, CustomerService>()); x.Add(new TypeAction <IRepository, Repository>()); x.Add(new TypeAction <IProvider, StringProvider>()); }); var service = container.GetInstance <ICustomerService>(); service.Get().Count().ShouldBeGreaterThan(2); service.Get2().ShouldNotBeNull(); }
public void can_register_the_same_type_interface_multiple_times() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <IProvider, StringProvider>()); x.Add(new TypeAction <IProvider, MemoryProvider>()); }); var instances = container.GetAllInstances <IProvider>(); foreach (IProvider instance in instances) { instance.Get().ShouldNotBeNull(); } }
public void can_pick_ctor_for_construction() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <ICustomer, Customer>()); x.Add(new TypeAction(typeof(IClassWithMoreThan1Ctor), typeof(ClassWithMoreThan1Ctor)) { Ctor = new[] { typeof(ICustomer) } }); }); var item = container.GetInstance <IClassWithMoreThan1Ctor>(); item.ReceivedValues.Count.ShouldEqual(1); item.ReceivedValues.First().Value.ShouldBeType <Customer>(); }
public void can_scan_assembly_and_register_types() { var container = TypeRegistry.Construct(x => { x.TypeScanner(new[] { typeof(ICustomer).Assembly }); x.AddTypeScanner(new CustomTypeScanner()); }); var repo = container.GetInstance <IRepository>(); repo.ShouldNotBeNull(); var test = container.GetInstance <UsedForScannerOnly>(); test.Name.ShouldEqual(typeof(UsedForScannerOnly).Name); }
public void can_proxy_object() { var proxy = new ProxyGenerator(); var container = TypeRegistry.Construct(x => x.Add(new TypeAction <ICustomer, Customer> { AfterCreationDoThis = f => { f.Name = "this is a test"; return(proxy.CreateInterfaceProxyWithTargetInterface(f, new TestInterceptor())); } })); var customer = container.GetInstance <ICustomer>(); customer.GetName().ShouldEqual("not your test name"); }
public void can_add_type_with_name2() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <IProvider, StringProvider> { Key = "StringProvider" }); x.Add(new TypeAction <IProvider, MemoryProvider> { Key = "MemoryProvider" }); }); var instance = (IProvider)container.GetInstance(typeof(IProvider), "StringProvider"); instance.ShouldNotBeNull(); instance.Get().ShouldEqual("StringProvider"); }
public void can_have_a_singleton_life_cycle() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <IRepository, Repository> { LifeSpan = new SingletonLifeSpan() }); x.Add(new TypeAction <IProvider, StringProvider>()); }); var expected = container.GetInstance <IRepository>().GuidTest(); var actual = container.GetInstance <IRepository>().GuidTest(); expected.ShouldEqual(actual); }
public void can_inject_property() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <ICustomer, Customer> { AfterCreationDoThis = a => { a.Name = "this is a test"; return(a); } }); }); var customer = container.GetInstance <ICustomer>(); customer.Name.ShouldEqual("this is a test"); }
public static void Start() { var container = TypeRegistry.Construct(x => { x.Add(new TypeAction <ICustomer, Customer> { AfterCreationDoThis = p => { p.Name = "tom test"; return(p); } }); x.Add(new TypeAction <IRepository, Repository> { LifeSpan = new SessionSingleton() }); }); DependencyResolver.SetResolver(new TypeCreatorDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new TypeCreatorDependencyResolver(container); }