コード例 #1
0
        public void select_interceptors()
        {
            var activator1 = new ActivatorInterceptor<ITarget>(x => x.Activate());
            var activator2 = new ActivatorInterceptor<Target>(x => x.UseSession(null));
            var activator3 = new ActivatorInterceptor<Target>(x => x.ThrowUp());
            var activator4 = new ActivatorInterceptor<ITarget>(x => x.Debug());
            var activator5 = new ActivatorInterceptor<IGateway>(x => x.DoSomething());

            var policies = new Policies();
            policies.Add(activator1.ToPolicy());
            policies.Add(activator2.ToPolicy());
            policies.Add(activator3.ToPolicy());
            policies.Add(activator4.ToPolicy());
            policies.Add(activator5.ToPolicy());

            var instance1 = new SmartInstance<Target>();
            policies.Apply(typeof(ITarget), instance1);
            instance1.Interceptors
                .ShouldHaveTheSameElementsAs(activator1, activator2, activator3, activator4);

            var instance2 = new SmartInstance<ATarget>();
            policies.Apply(typeof(ITarget), instance2);
            instance2.Interceptors
                .ShouldHaveTheSameElementsAs(activator1, activator4);

            var instance3 = new SmartInstance<StubbedGateway>();
            policies.Apply(typeof(ITarget), instance3);
            instance3.Interceptors
                .ShouldHaveTheSameElementsAs(activator5);
        }
コード例 #2
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance<ExceptionHandlerBehavior>();
            instance.Ctor<HandlerChain>().Is(_chain);

            return instance;
        }
コード例 #3
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance<BehaviorTracer>();
            instance.Ctor<BehaviorNode>().Is(Next);

            return instance;
        }
コード例 #4
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance<AntiForgeryBehavior>();
            instance.Ctor<string>().Is(_salt);

            return instance;
        }
コード例 #5
0
        public void release_from_the_cache()
        {
            var cache = new TrackingTransientCache();

            var instance = new SmartInstance<Target>();
            var session = new FakeBuildSession();

            var t1 = cache.Get(typeof(Target), instance, session).As<Target>();
            var t2 = cache.Get(typeof(Target), instance, session).As<Target>();
            var t3 = cache.Get(typeof(Target), instance, session).As<Target>();

            // pre-conditions
            t2.WasDisposed.ShouldBeFalse();
            cache.Tracked.ShouldHaveTheSameElementsAs(t1, t2, t3);


            cache.Release(t2);

            // only t2 should be disposed
            t1.WasDisposed.ShouldBeFalse();
            t2.WasDisposed.ShouldBeTrue();
            t3.WasDisposed.ShouldBeFalse();

            // t2 should be removed from tracked
            cache.Tracked.ShouldHaveTheSameElementsAs(t1, t3);
        }
コード例 #6
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance <BehaviorTracer>();

            instance.Ctor <BehaviorNode>().Is(Next);

            return(instance);
        }
コード例 #7
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance <AntiForgeryBehavior>();

            instance.Ctor <string>().Is(_salt);

            return(instance);
        }
コード例 #8
0
 public CacheServiceRegistry(SmartInstance <TConcreteType, TPluginType> smartInstance)
 {
     smartInstance.AddInterceptor(new DynamicProxyInterceptor <TPluginType>(new IInterceptionBehavior[]
     {
         new CachingInterceptor(),
         new CacheInvalidateInterceptor(),
     }));
 }
コード例 #9
0
        public SmartInstance <TPluggedType> Add <TPluggedType>()
        {
            var instance = new SmartInstance <TPluggedType>();

            Add(instance);

            return(instance);
        }
コード例 #10
0
ファイル: ProfileExpression.cs プロジェクト: hasaki/ragetanks
            /// <summary>
            /// For this profile, use this concrete type
            /// </summary>
            /// <typeparam name="CONCRETETYPE"></typeparam>
            /// <returns></returns>
            public SmartInstance <CONCRETETYPE> Use <CONCRETETYPE>()
            {
                var instance = new SmartInstance <CONCRETETYPE>();

                Use(instance);

                return(instance);
            }
コード例 #11
0
        /// <summary>
        /// Specify the default Instance of this PluginType by a concrete type
        /// </summary>
        public SmartInstance <TConcreteType, TPluginType> Use <TConcreteType>() where TConcreteType : TPluginType
        {
            var instance = new SmartInstance <TConcreteType, TPluginType>();

            registerDefault(instance);

            return(instance);
        }
コード例 #12
0
        /// <summary>
        /// Add a new Instance to this PluginType by concrete type
        /// </summary>
        /// <typeparam name="TPluggedType"></typeparam>
        /// <returns></returns>
        public SmartInstance <TPluggedType, TPluginType> Add <TPluggedType>() where TPluggedType : TPluginType
        {
            var instance = new SmartInstance <TPluggedType, TPluginType>();

            AddInstance(instance);

            return(instance);
        }
コード例 #13
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance <ExceptionHandlerBehavior>();

            instance.Ctor <HandlerChain>().Is(_chain);

            return(instance);
        }
コード例 #14
0
        public FubuTransportServiceRegistry(string mode)
        {
            var eventAggregatorDef = mode.InTesting()
                ? new SmartInstance <SynchronousEventAggregator>()
                : (Instance) new SmartInstance <EventAggregator>();

            eventAggregatorDef.SetLifecycleTo <SingletonLifecycle>();
            SetServiceIfNone(typeof(IEventAggregator), eventAggregatorDef);



            var stateCacheDef = new SmartInstance <SagaStateCacheFactory>();

            stateCacheDef.Singleton();
            SetServiceIfNone(typeof(ISagaStateCacheFactory), stateCacheDef);

            SetServiceIfNone <IChainInvoker, ChainInvoker>();
            SetServiceIfNone <IEnvelopeSender, EnvelopeSender>();

            AddService <IMessageSerializer, XmlMessageSerializer>();
            AddService <IMessageSerializer, JsonMessageSerializer>();

            AddService <IActivator, ServiceBusActivator>();

            SetServiceIfNone <IServiceBus, ServiceBus>();

            SetServiceIfNone <IEnvelopeSerializer, EnvelopeSerializer>();
            SetServiceIfNone <IHandlerPipeline, HandlerPipeline>();


            AddService <ILogListener, EventAggregationListener>();

            if (mode.InTesting())
            {
                var def = new SmartInstance <MessagingSession>();
                def.Singleton();
                SetServiceIfNone(typeof(IMessagingSession), def);
                AddService <ILogListener, MessageRecordListener>();
            }


            if (mode.InTesting())
            {
                AddService <IActivator, TransportCleanupActivator>();
            }

            AddService <IEnvelopeHandler, DelayedEnvelopeHandler>();
            AddService <IEnvelopeHandler, ResponseEnvelopeHandler>();
            AddService <IEnvelopeHandler, ChainExecutionEnvelopeHandler>();
            AddService <IEnvelopeHandler, NoSubscriberHandler>();

            SetServiceIfNone <IMessageExecutor, MessageExecutor>();
            SetServiceIfNone <IOutgoingSender, OutgoingSender>();



            subscriptions();
        }
コード例 #15
0
        public FubuTransportServiceRegistry(string mode)
        {
            var eventAggregatorDef =mode.InTesting()
                ? new SmartInstance<SynchronousEventAggregator>()
                : (Instance)new SmartInstance<EventAggregator>();

            eventAggregatorDef.SetLifecycleTo<SingletonLifecycle>();
            SetServiceIfNone(typeof(IEventAggregator), eventAggregatorDef);



            var stateCacheDef = new SmartInstance<SagaStateCacheFactory>();
            stateCacheDef.Singleton();
            SetServiceIfNone(typeof(ISagaStateCacheFactory), stateCacheDef);

            SetServiceIfNone<IChainInvoker, ChainInvoker>();
            SetServiceIfNone<IEnvelopeSender, EnvelopeSender>();

            ForSingletonOf<IMessageSerializer>().Use<XmlMessageSerializer>();
            AddService<IMessageSerializer, JsonMessageSerializer>();

            AddService<IActivator, ServiceBusActivator>();

            SetServiceIfNone<IServiceBus, ServiceBus>();

            SetServiceIfNone<IEnvelopeSerializer, EnvelopeSerializer>();
            SetServiceIfNone<IHandlerPipeline, HandlerPipeline>();


            AddService<ILogListener, EventAggregationListener>();

            if (mode.InTesting())
            {
                var def = new SmartInstance<MessagingSession>();
                def.Singleton();
                SetServiceIfNone(typeof(IMessagingSession), def);
                AddService<ILogListener, MessageRecordListener>();
            }


            if (mode.InTesting())
            {
                AddService<IActivator, TransportCleanupActivator>();
            }

            AddService<IEnvelopeHandler, DelayedEnvelopeHandler>();
            AddService<IEnvelopeHandler, ResponseEnvelopeHandler>();
            AddService<IEnvelopeHandler, ChainExecutionEnvelopeHandler>();
            AddService<IEnvelopeHandler, NoSubscriberHandler>();

            SetServiceIfNone<IMessageExecutor, MessageExecutor>();
            SetServiceIfNone<IOutgoingSender, OutgoingSender>();



            subscriptions();
        }
コード例 #16
0
        public void set_default()
        {
            var family   = new PluginFamily(typeof(IServiceProvider));
            var instance = new SmartInstance <DataSet>();

            family.SetDefault(instance);

            family.GetDefaultInstance().ShouldBeTheSameAs(instance);
        }
コード例 #17
0
        public void find_instance_positive()
        {
            var graph    = PluginGraph.CreateRoot();
            var instance = new SmartInstance <BigThingy>().Named("red");

            graph.Families[typeof(BigThingy)].AddInstance(instance);

            graph.FindInstance(typeof(BigThingy), "red").ShouldBeTheSameAs(instance);
        }
コード例 #18
0
        public void reflecting_over_constructor_args()
        {
            IConfiguredInstance instance = new SmartInstance <GuyWithArguments>()
                                           // I'm just forcing it to assign the constructor function
                                           .SelectConstructor(() => new GuyWithArguments(null, null));

            instance.Constructor.GetParameters().Select(x => x.Name)
            .ShouldHaveTheSameElementsAs("widget", "rule");
        }
コード例 #19
0
        public void reflecting_over_constructor_args()
        {
            IConfiguredInstance instance = new SmartInstance<GuyWithArguments>()
                // I'm just forcing it to assign the constructor function
                .SelectConstructor(() => new GuyWithArguments(null, null));

            instance.Constructor.GetParameters().Select(x => x.Name)
                .ShouldHaveTheSameElementsAs("widget", "rule");
        }
コード例 #20
0
        private SmartInstance <T> instanceOf <T>()
        {
            var instance = new SmartInstance <T>();

            structuredInstance = instance;
            configuredInstance = instance;

            return(instance);
        }
コード例 #21
0
        public void find_instance_can_use_missing_instance()
        {
            var graph    = new PluginGraph();
            var instance = new SmartInstance <BigThingy>().Named("red");

            graph.Families[typeof(BigThingy)].MissingInstance = instance;

            graph.FindInstance(typeof(BigThingy), "green")
            .ShouldBeTheSameAs(instance);
        }
コード例 #22
0
        /// <summary>
        /// Shorthand way of saying Use<>
        /// </summary>
        /// <typeparam name="CONCRETETYPE"></typeparam>
        /// <returns></returns>
        public SmartInstance <CONCRETETYPE> Use <CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE
        {
            // This is *my* team's naming convention for generic parameters
            // I know you may not like it, but it's my article so there
            var instance = new SmartInstance <CONCRETETYPE>();

            registerDefault(instance);

            return(instance);
        }
コード例 #23
0
        /// <summary>
        /// Shorthand way of saying Use<>
        /// </summary>
        /// <typeparam name="TConcreteType"></typeparam>
        /// <returns></returns>
        public SmartInstance <TConcreteType> Use <TConcreteType>() where TConcreteType : TPluginType
        {
            // This is *my* team's naming convention for generic parameters
            // I know you may not like it, but it's my article so there
            var instance = new SmartInstance <TConcreteType>();

            registerDefault(instance);

            return(instance);
        }
コード例 #24
0
        private void subscriptions()
        {
            var subscriberDef = new SmartInstance<SubscriptionCache>();
            subscriberDef.Singleton();
            SetServiceIfNone(typeof (ISubscriptionCache), subscriberDef);

            SetServiceIfNone<ISubscriptionRepository, SubscriptionRepository>();

            SetServiceIfNone<ISubscriptionPersistence>(new InMemorySubscriptionPersistence());
        }
コード例 #25
0
        public T build <T>(Action <SmartInstance <T> > action)
        {
            SmartInstance <T> instance = For <T>();

            action(instance);

            var container = new Container(r => r.For <T>().Use(instance));

            return(container.GetInstance <T>());
        }
コード例 #26
0
        public T build <T>(Action <SmartInstance <T> > action)
        {
            SmartInstance <T> instance = instanceOf <T>();

            action(instance);

            var container = new Container(r => r.ForRequestedType <T>().TheDefault.IsThis(instance));

            return(container.GetInstance <T>());
        }
コード例 #27
0
        public void add_interceptor()
        {
            var interceptor =
                new ActivatorInterceptor <SimpleWidget>(w => w.Intercept());
            var instance = new SmartInstance <SimpleWidget>();

            instance.AddInterceptor(interceptor);

            new Container().GetInstance <SimpleWidget>(instance)
            .WasIntercepted.ShouldBeTrue();
        }
コード例 #28
0
        private void subscriptions()
        {
            var subscriberDef = new SmartInstance <SubscriptionCache>();

            subscriberDef.Singleton();
            SetServiceIfNone(typeof(ISubscriptionCache), subscriberDef);

            SetServiceIfNone <ISubscriptionRepository, SubscriptionRepository>();

            SetServiceIfNone <ISubscriptionPersistence>(new InMemorySubscriptionPersistence());
        }
コード例 #29
0
        public void add_interceptor()
        {
            var interceptor =
                new ActivatorInterceptor<SimpleWidget>(w => w.Intercept());
            var instance = new SmartInstance<SimpleWidget>();

            instance.AddInterceptor(interceptor);

            new Container().GetInstance<SimpleWidget>(instance)
                .WasIntercepted.ShouldBeTrue();
        }
コード例 #30
0
        /// <summary>
        /// Decorates all instances of TPluginType with the concrete type TDecoratorType
        /// </summary>
        public SmartInstance <TDecoratorType, TPluginType> DecorateAllWith <TDecoratorType>(Func <Instance, bool> filter = null)
            where TDecoratorType : TPluginType
        {
            var instance    = new SmartInstance <TDecoratorType, TPluginType>();
            var interceptor = new DecoratorInterceptor(typeof(TPluginType), instance);
            var policy      = new InterceptorPolicy <TPluginType>(interceptor, filter);

            alter = graph => graph.Policies.Add(policy);

            return(instance);
        }
コード例 #31
0
        public void find_instance_can_use_missing_instance()
        {
            var graph    = PluginGraph.CreateRoot();
            var instance = new SmartInstance <BigThingy>().Named("red");

            graph.Families[typeof(BigThingy)].MissingInstance = instance;

            var cloned_and_renamed = graph.FindInstance(typeof(BigThingy), "green").ShouldBeAssignableTo <ConfiguredInstance>();

            cloned_and_renamed.Name.ShouldBe("green");
            cloned_and_renamed.PluggedType.ShouldBe(typeof(BigThingy));
        }
コード例 #32
0
        public void SetUp()
        {
            PluginCache.ResetAll();
            builder  = PluginCache.FindBuilder(typeof(ClassWithMixOfSetters));
            instance = new SmartInstance <ClassWithMixOfSetters>().WithCtorArg("Age").EqualTo(34);
            _session = new BuildSession();

            TheDefaultGateway = new DefaultGateway();
            _session.RegisterDefault(typeof(IGateway), TheDefaultGateway);

            _target = null;
        }
コード例 #33
0
ファイル: BuildUpTester.cs プロジェクト: rhyss/structuremap
        public void SetUp()
        {
            TheDefaultGateway = new DefaultGateway();

            var args = new ExplicitArguments();
            args.Set<IGateway>(TheDefaultGateway);

            builder = new Plugin(typeof (ClassWithMixOfSetters)).CreateBuilder();
            instance = new SmartInstance<ClassWithMixOfSetters>().Ctor<int>("Age").Is(34);
            _session = BuildSession.Empty(args);

            _target = null;
        }
コード例 #34
0
        protected override IConfiguredInstance buildInstance()
        {
            var instance = new SmartInstance <AuthorizationBehavior>();

            instance.Ctor <IAuthorizationNode>().Is(this);

            if (_failure != null)
            {
                instance.Ctor <IAuthorizationFailureHandler>().Is(_failure);
            }

            return(instance);
        }
コード例 #35
0
ファイル: SMSelectorExpression.cs プロジェクト: juandrn/NetXP
 internal void Register(
     CreatePluginFamilyExpression <TInter> @for,
     SmartInstance <TImpl, TInter> use,
     string instanceName,
     DILifeTime lifetime,
     Action <DILifeTime, LambdaInstance <TImpl, TInter> > setLifeTime)
 {
     this.@for         = @for;
     this.use          = use;
     this.instanceName = instanceName;
     this.lifetime     = lifetime;
     this.setLifeTime  = setLifeTime;
 }
コード例 #36
0
        public void SetUp()
        {
            TheDefaultGateway = new DefaultGateway();

            var args = new ExplicitArguments();

            args.Set <IGateway>(TheDefaultGateway);

            builder  = new Plugin(typeof(ClassWithMixOfSetters)).CreateBuilder();
            instance = new SmartInstance <ClassWithMixOfSetters>().Ctor <int>("Age").Is(34);
            _session = BuildSession.Empty(args);

            _target = null;
        }
コード例 #37
0
        public void dependency_with_setter_with_instance()
        {
            var instance
                = new ConfiguredInstance(typeof(GuyWithProperties));
            var prop = instance.PluggedType.GetProperty("Widget");

            var dependency = new SmartInstance<AWidget>();
            instance.Dependencies.AddForProperty(prop, dependency);

            var container = new Container();

            container.GetInstance<GuyWithProperties>(instance)
                .Widget.ShouldBeOfType<AWidget>();
        }
コード例 #38
0
        public void get_builds_a_new_object_everytime_it_is_called()
        {
            var cache = new TrackingTransientCache();

            var instance = new SmartInstance<Target>();
            var session = new FakeBuildSession();

            var t1 = cache.Get(typeof (Target), instance, session);
            var t2 = cache.Get(typeof (Target), instance, session);
            var t3 = cache.Get(typeof (Target), instance, session);

            t1.ShouldNotBeTheSameAs(t2);
            t1.ShouldNotBeTheSameAs(t3);
            t2.ShouldNotBeTheSameAs(t3);
        }
コード例 #39
0
        public void dependency_with_setter_with_instance()
        {
            var instance
                = new ConfiguredInstance(typeof(GuyWithProperties));
            var prop = instance.PluggedType.GetProperty("Widget");

            var dependency = new SmartInstance <AWidget>();

            instance.Dependencies.AddForProperty(prop, dependency);

            var container = new Container();

            container.GetInstance <GuyWithProperties>(instance)
            .Widget.ShouldBeOfType <AWidget>();
        }
コード例 #40
0
        public void get_builds_a_new_object_everytime_it_is_called()
        {
            var cache = new TrackingTransientCache();

            var instance = new SmartInstance <Target>();
            var session  = new FakeBuildSession();

            var t1 = cache.Get(typeof(Target), instance, session);
            var t2 = cache.Get(typeof(Target), instance, session);
            var t3 = cache.Get(typeof(Target), instance, session);

            t1.ShouldNotBeTheSameAs(t2);
            t1.ShouldNotBeTheSameAs(t3);
            t2.ShouldNotBeTheSameAs(t3);
        }
コード例 #41
0
        public void remove_all_clears_the_defaul_and_removes_all_plugins_instances()
        {
            var family   = new PluginFamily(typeof(IServiceProvider));
            var instance = new SmartInstance <DataSet>();

            family.SetDefault(instance);

            family.AddInstance(new NullInstance());
            family.AddType(typeof(DataSet));

            family.RemoveAll();

            family.DefaultInstanceKey.ShouldBeNull();

            family.InstanceCount.ShouldEqual(0);
        }
コード例 #42
0
        public CreatePluginFamilyExpression <PLUGINTYPE> AddConcreteType <PLUGGEDTYPE>()
        {
            if (!PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).CanBeAutoFilled)
            {
                throw new StructureMapException(231);
            }

            _alterations.Add(family =>
            {
                string name = PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).ConcreteKey;
                SmartInstance <PLUGGEDTYPE> instance = new SmartInstance <PLUGGEDTYPE>().WithName(name);
                family.AddInstance(instance);
            });

            return(this);
        }
コード例 #43
0
        public void dispose_and_clear_all()
        {
            var cache = new TrackingTransientCache();

            var instance = new SmartInstance<Target>();
            var session = new FakeBuildSession();

            var t1 = cache.Get(typeof(Target), instance, session).As<Target>();
            var t2 = cache.Get(typeof(Target), instance, session).As<Target>();
            var t3 = cache.Get(typeof(Target), instance, session).As<Target>();


            cache.DisposeAndClear();

            cache.Tracked.Any().ShouldBeFalse();

            t1.WasDisposed.ShouldBeTrue();
            t2.WasDisposed.ShouldBeTrue();
            t3.WasDisposed.ShouldBeTrue();
        }
コード例 #44
0
        public void pushing_the_same_instance_will_throw_a_bidirectional_dependency_exception()
        {
            var session = BuildSession.ForPluginGraph(new PluginGraph());

            var instance1 = new SmartInstance<StubbedGateway>();
            var instance2 = new SmartInstance<ARule>();
            var instance3 = new SmartInstance<AWidget>();

            session.Push(instance1);
            session.Push(instance2);
            session.Push(instance3);

            var ex = Exception<StructureMapBuildException>.ShouldBeThrownBy(() => { session.Push(instance1); });

            ex.Message.ShouldContain("Bi-directional dependency relationship detected!");
        }