public void SetUp()
        {
            _lastService = null;
            recorder     = new ContextRecorder();

            // SAMPLE: interceptors-by-instance
            _container = new Container(r =>
            {
                r.For <ContextRecorder>().Use(recorder);


                r.For <IService>().AddInstances(x =>
                {
                    x.Type <ColorService>()
                    // Registers an activation action on this Instance
                    .OnCreation("last service", s => _lastService = s)
                    .Named("Intercepted")
                    .Ctor <string>("color").Is("Red");

                    x.Type <ColorService>()
                    // Activation using IContext
                    .OnCreation("last touched", (c, s) => c.GetInstance <ContextRecorder>().WasTouched = true)
                    .Named("InterceptedWithContext")
                    .Ctor <string>("color").Is("Red");

                    x.Type <ColorService>()
                    .Named("NotIntercepted")
                    .Ctor <string>("color").Is("Blue");

                    x.Object(new ColorService("Yellow"))
                    .Named("Yellow")
                    .OnCreation("set the last service", s => _lastService = s);

                    x.ConstructedBy(() => new ColorService("Purple")).Named("Purple")
                    // Applies a decorator to this instance. Not sure *why*
                    // you'd want to do it this way
                    .DecorateWith(s => new DecoratorService(s));

                    x.ConstructedBy(() => new ColorService("Purple")).Named("DecoratedWithContext")
                    // Fancier decorator
                    .DecorateWith("decorated with context", (c, s) =>
                    {
                        c.GetInstance <ContextRecorder>().WasTouched = true;
                        return(new DecoratorService(s));
                    });

                    x.Type <ColorService>().Named("Decorated").DecorateWith(
                        s => new DecoratorService(s))
                    .Ctor <string>("color").Is("Orange");

                    x.Object(new ColorService("Yellow")).Named("Bad")
                    .OnCreation("throw exception", obj => { throw new ApplicationException("Bad!"); });
                });
                // ENDSAMPLE
            });
        }
Esempio n. 2
0
        public void SetUp()
        {
            _lastService = null;
            recorder = new ContextRecorder();

            // SAMPLE: interceptors-by-instance
            _container = new Container(r =>
            {
                r.For<ContextRecorder>().Use(recorder);


                r.For<IService>().AddInstances(x =>
                {
                    x.Type<ColorService>()
                        // Registers an activation action on this Instance
                        .OnCreation("last service", s => _lastService = s)
                        .Named("Intercepted")
                        .Ctor<string>("color").Is("Red");

                    x.Type<ColorService>()
                        // Activation using IContext
                        .OnCreation("last touched", (c, s) => c.GetInstance<ContextRecorder>().WasTouched = true)
                        .Named("InterceptedWithContext")
                        .Ctor<string>("color").Is("Red");

                    x.Type<ColorService>()
                        .Named("NotIntercepted")
                        .Ctor<string>("color").Is("Blue");

                    x.Object(new ColorService("Yellow"))
                        .Named("Yellow")
                        .OnCreation("set the last service", s => _lastService = s);

                    x.ConstructedBy(() => new ColorService("Purple")).Named("Purple")
                        // Applies a decorator to this instance. Not sure *why*
                        // you'd want to do it this way
                        .DecorateWith(s => new DecoratorService(s));

                    x.ConstructedBy(() => new ColorService("Purple")).Named("DecoratedWithContext")
                        // Fancier decorator
                        .DecorateWith("decorated with context", (c, s) =>
                        {
                            c.GetInstance<ContextRecorder>().WasTouched = true;
                            return new DecoratorService(s);
                        });

                    x.Type<ColorService>().Named("Decorated").DecorateWith(
                        s => new DecoratorService(s))
                        .Ctor<string>("color").Is("Orange");

                    x.Object(new ColorService("Yellow")).Named("Bad")
                        .OnCreation("throw exception", obj => { throw new ApplicationException("Bad!"); });
                });
                // ENDSAMPLE
            });
        }
Esempio n. 3
0
        public void SetUp()
        {
            _lastService = null;
            recorder     = new ContextRecorder();

            _container = new Container(r =>
            {
                r.ForRequestedType <ContextRecorder>().TheDefault.IsThis(recorder);

                r.ForRequestedType <IService>().AddInstances(x =>
                {
                    x.OfConcreteType <ColorService>()
                    .OnCreation(s => _lastService = s)
                    .WithName("Intercepted")
                    .WithCtorArg("color").EqualTo("Red");

                    x.OfConcreteType <ColorService>()
                    .OnCreation((c, s) => c.GetInstance <ContextRecorder>().WasTouched = true)
                    .WithName("InterceptedWithContext")
                    .WithCtorArg("color").EqualTo("Red");

                    x.OfConcreteType <ColorService>()
                    .WithName("NotIntercepted")
                    .WithCtorArg("color").EqualTo("Blue");

                    x.Object(new ColorService("Yellow"))
                    .WithName("Yellow")
                    .OnCreation <ColorService>(s => _lastService = s);

                    x.ConstructedBy(() => new ColorService("Purple")).WithName("Purple")
                    .EnrichWith <IService>(s => new DecoratorService(s));

                    x.ConstructedBy(() => new ColorService("Purple")).WithName("DecoratedWithContext")
                    .EnrichWith <IService>((c, s) =>
                    {
                        c.GetInstance <ContextRecorder>().WasTouched = true;
                        return(new DecoratorService(s));
                    });

                    x.OfConcreteType <ColorService>().WithName("Decorated").EnrichWith <IService>(
                        s => new DecoratorService(s))
                    .WithCtorArg("color").EqualTo("Orange");

                    x.Object(new ColorService("Yellow")).WithName("Bad")
                    .OnCreation <ColorService>(obj => { throw new ApplicationException("Bad!"); });
                });
            });
        }
Esempio n. 4
0
        public void SetUp()
        {
            _lastService = null;
            recorder     = new ContextRecorder();

            _container = new Container(r =>
            {
                r.For <ContextRecorder>().Use(recorder);

                r.For <IService>().AddInstances(x =>
                {
                    x.Type <ColorService>()
                    .OnCreation("last service", s => _lastService = s)
                    .Named("Intercepted")
                    .Ctor <string>("color").Is("Red");

                    x.Type <ColorService>()
                    .OnCreation("last touched", (c, s) => c.GetInstance <ContextRecorder>().WasTouched = true)
                    .Named("InterceptedWithContext")
                    .Ctor <string>("color").Is("Red");

                    x.Type <ColorService>()
                    .Named("NotIntercepted")
                    .Ctor <string>("color").Is("Blue");

                    x.Object(new ColorService("Yellow"))
                    .Named("Yellow")
                    .OnCreation("set the last service", s => _lastService = s);

                    x.ConstructedBy(() => new ColorService("Purple")).Named("Purple")
                    .DecorateWith(s => new DecoratorService(s));

                    x.ConstructedBy(() => new ColorService("Purple")).Named("DecoratedWithContext")
                    .DecorateWith("decorated with context", (c, s) =>
                    {
                        c.GetInstance <ContextRecorder>().WasTouched = true;
                        return(new DecoratorService(s));
                    });

                    x.Type <ColorService>().Named("Decorated").DecorateWith(
                        s => new DecoratorService(s))
                    .Ctor <string>("color").Is("Orange");

                    x.Object(new ColorService("Yellow")).Named("Bad")
                    .OnCreation("throw exception", obj => { throw new ApplicationException("Bad!"); });
                });
            });
        }
Esempio n. 5
0
        public void SetUp()
        {
            _lastService = null;
            recorder = new ContextRecorder();

            _container = new Container(r => {
                r.For<ContextRecorder>().Use(recorder);

                r.For<IService>().AddInstances(x => {
                    x.Type<ColorService>()
                        .OnCreation("last service",s => _lastService = s)
                        .Named("Intercepted")
                        .Ctor<string>("color").Is("Red");

                    x.Type<ColorService>()
                        .OnCreation("last touched", (c, s) => c.GetInstance<ContextRecorder>().WasTouched = true)
                        .Named("InterceptedWithContext")
                        .Ctor<string>("color").Is("Red");

                    x.Type<ColorService>()
                        .Named("NotIntercepted")
                        .Ctor<string>("color").Is("Blue");

                    x.Object(new ColorService("Yellow"))
                        .Named("Yellow")
                        .OnCreation("set the last service", s => _lastService = s);

                    x.ConstructedBy(() => new ColorService("Purple")).Named("Purple")
                        .DecorateWith(s => new DecoratorService(s));

                    x.ConstructedBy(() => new ColorService("Purple")).Named("DecoratedWithContext")
                        .DecorateWith("decorated with context", (c, s) => {
                            c.GetInstance<ContextRecorder>().WasTouched = true;
                            return new DecoratorService(s);
                        });

                    x.Type<ColorService>().Named("Decorated").DecorateWith(
                        s => new DecoratorService(s))
                        .Ctor<string>("color").Is("Orange");

                    x.Object(new ColorService("Yellow")).Named("Bad")
                        .OnCreation("throw exception", obj => { throw new ApplicationException("Bad!"); });
                });
            });
        }
Esempio n. 6
0
        public void SetUp()
        {
            _lastService = null;
            recorder = new ContextRecorder();

            _container = new Container(r =>
            {
                r.ForRequestedType<ContextRecorder>().TheDefault.IsThis(recorder);

                r.ForRequestedType<IService>().AddInstances(x =>
                {
                    x.OfConcreteType<ColorService>()
                        .OnCreation(s => _lastService = s)
                        .WithName("Intercepted")
                        .WithCtorArg("color").EqualTo("Red");

                    x.OfConcreteType<ColorService>()
                        .OnCreation((c, s) => c.GetInstance<ContextRecorder>().WasTouched = true)
                        .WithName("InterceptedWithContext")
                        .WithCtorArg("color").EqualTo("Red");

                    x.OfConcreteType<ColorService>()
                        .WithName("NotIntercepted")
                        .WithCtorArg("color").EqualTo("Blue");

                    x.Object(new ColorService("Yellow"))
                        .WithName("Yellow")
                        .OnCreation<ColorService>(s => _lastService = s);

                    x.ConstructedBy(() => new ColorService("Purple")).WithName("Purple")
                        .EnrichWith<IService>(s => new DecoratorService(s));

                    x.ConstructedBy(() => new ColorService("Purple")).WithName("DecoratedWithContext")
                        .EnrichWith<IService>((c, s) =>
                        {
                            c.GetInstance<ContextRecorder>().WasTouched = true;
                            return new DecoratorService(s);
                        });

                    x.OfConcreteType<ColorService>().WithName("Decorated").EnrichWith<IService>(
                        s => new DecoratorService(s))
                        .WithCtorArg("color").EqualTo("Orange");

                    x.Object(new ColorService("Yellow")).WithName("Bad")
                        .OnCreation<ColorService>(obj => { throw new ApplicationException("Bad!"); });
                });
            });
        }