Ejemplo n.º 1
0
        public void NowDoItWith_Container_Itself_with_new_API()
        {
            var container = new Container(x => {
                x.For <ExplicitTarget>().Use <ExplicitTarget>()
                .Ctor <IProvider>().IsSpecial(child => child.Type <RedProvider>())
                .Ctor <string>("name").Is("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            container.GetInstance <ExplicitTarget>().Provider.IsType <RedProvider>();

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();

            container.With <IProvider>(theBlueProvider).GetInstance <ExplicitTarget>()
            .Provider.ShouldBeTheSameAs(theBlueProvider);
        }
        public void NowDoItWithObjectFactoryItself_with_new_API()
        {
            ObjectFactory.Initialize(x =>
            {
                x.For <ExplicitTarget>().Use <ExplicitTarget>()
                .CtorDependency <IProvider>().Is(child => child.OfConcreteType <RedProvider>())
                .WithCtorArg("name").EqualTo("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            ObjectFactory.GetInstance <ExplicitTarget>().Provider.IsType <RedProvider>();

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();

            ObjectFactory.With <IProvider>(theBlueProvider).GetInstance <ExplicitTarget>()
            .Provider.ShouldBeTheSameAs(theBlueProvider);
        }
Ejemplo n.º 3
0
        public void NowDoItWithObjectFactoryItself()
        {
            var container = new Container(x => {
                x.ForConcreteType <ExplicitTarget>().Configure
                .Ctor <IProvider>().Is <RedProvider>()
                .Ctor <string>("name").Is("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            var firstTarget = container.GetInstance <ExplicitTarget>();

            firstTarget.Provider.ShouldBeOfType <RedProvider>();

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();
            var secondTarget    = container.With <IProvider>(theBlueProvider).GetInstance <ExplicitTarget>();

            Assert.AreSame(theBlueProvider, secondTarget.Provider);
        }
        public void NowDoItWithObjectFactoryItself()
        {
            ObjectFactory.Initialize(x =>
            {
                x.ForConcreteType <ExplicitTarget>().Configure
                .CtorDependency <IProvider>().Is <RedProvider>()
                .WithCtorArg("name").EqualTo("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            var firstTarget = ObjectFactory.GetInstance <ExplicitTarget>();

            Assert.IsInstanceOfType(typeof(RedProvider), firstTarget.Provider);

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();
            var secondTarget    = ObjectFactory.With <IProvider>(theBlueProvider).GetInstance <ExplicitTarget>();

            Assert.AreSame(theBlueProvider, secondTarget.Provider);
        }
Ejemplo n.º 5
0
        public void NowDoItWithObjectFactoryItself_with_new_API()
        {
            ObjectFactory.Initialize(x =>
            {
                x.For<ExplicitTarget>().Use<ExplicitTarget>()
                    .Ctor<IProvider>().Is(child => child.Type<RedProvider>())
                    .Ctor<string>("name").Is("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            ObjectFactory.GetInstance<ExplicitTarget>().Provider.IsType<RedProvider>();

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();
            ObjectFactory.Container.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>()
                .Provider.ShouldBeTheSameAs(theBlueProvider);
        }
Ejemplo n.º 6
0
        public void NowDoItWithObjectFactoryItself()
        {
            ObjectFactory.Initialize(x =>
            {
                x.ForConcreteType<ExplicitTarget>().Configure
                    .Ctor<IProvider>().Is<RedProvider>()
                    .Ctor<string>("name").Is("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>();
            firstTarget.Provider.ShouldBeOfType<RedProvider>();

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();
            var secondTarget = ObjectFactory.Container.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>();
            Assert.AreSame(theBlueProvider, secondTarget.Provider);
        }
Ejemplo n.º 7
0
        public void NowDoItWithObjectFactoryItself()
        {
            ObjectFactory.Initialize(x =>
            {
                x.ForConcreteType<ExplicitTarget>().Configure
                    .CtorDependency<IProvider>().Is<RedProvider>()
                    .WithCtorArg("name").EqualTo("Jeremy");
            });

            // Get the ExplicitTarget without setting an explicit arg for IProvider
            var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>();
            Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider);

            // Now, set the explicit arg for IProvider
            var theBlueProvider = new BlueProvider();
            var secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>();
            Assert.AreSame(theBlueProvider, secondTarget.Provider);
        }