Esempio n. 1
0
        public DecoratedInstance <TTarget> AndThen <TDecorator>()
        {
            //Must be captured as a local variable, otherwise the closure's decorator will
            //always be the outer-most decorator, causing a Stack Overflow.
            var previousDecorator = _decorator;

            ContextEnrichmentHandler <TTarget> newDecorator = (ctx, t) =>
            {
                var pluginType = ctx.BuildStack.Current != null
                                                                ? ctx.BuildStack.Current.RequestedType
                                                                : typeof(TTarget);

                var innerInstance = previousDecorator(ctx, t);

                ctx.RegisterDefault(pluginType, innerInstance);

                return(ctx.GetInstance <TDecorator>());
            };

            _decorateCommand(newDecorator);

            _decorator = newDecorator;

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        ///     Register a Func to potentially enrich or substitute for the object
        ///     created by this Instance before it is returned to the caller
        /// </summary>
        /// <param name="handler"></param>
        /// <returns></returns>
        public SmartInstance <T> EnrichWith <TPluginType>(ContextEnrichmentHandler <TPluginType> handler)
        {
            var interceptor = new EnrichmentInterceptor <TPluginType>(handler);

            Interceptor = interceptor;

            return(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Register a Func to potentially enrich or substitute for the object
        /// created by this Instance before it is returned to the caller
        /// </summary>
        /// <param name="handler"></param>
        /// <returns></returns>
        public SmartInstance <T> EnrichWith <PLUGINTYPE>(ContextEnrichmentHandler <PLUGINTYPE> handler)
        {
            var interceptor = new EnrichmentInterceptor <PLUGINTYPE>(handler);

            Interceptor = interceptor;

            return(this);
        }
Esempio n. 4
0
        /// <summary>
        /// Register a Func to potentially enrich or substitute for the object
        /// created by this Instance before it is returned to the caller
        /// </summary>
        /// <param name="handler"></param>
        /// <returns></returns>
        public ConfiguredInstance EnrichWith <T>(ContextEnrichmentHandler <T> handler)
        {
            var interceptor = new EnrichmentInterceptor <T>(handler);

            Interceptor = interceptor;

            return(this);
        }
        /// <summary>
        /// Register a Func to potentially enrich or substitute for the object
        /// created by this Instance before it is returned to the caller
        /// </summary>
        /// <typeparam name="TYPE"></typeparam>
        /// <param name="handler"></param>
        /// <returns></returns>
        public T EnrichWith <TYPE>(ContextEnrichmentHandler <TYPE> handler)
        {
            var interceptor = new EnrichmentInterceptor <TYPE>(handler);

            Interceptor = interceptor;

            return(thisInstance);
        }
Esempio n. 6
0
        public DecoratorHelper(CreatePluginFamilyExpression <TTarget> target)
        {
            ContextEnrichmentHandler <TTarget> callback = (ctx, t) => t;

            _decorateCommand = e =>
            {
                callback = e;
            };

            target.EnrichAllWith((ctx, t) => callback(ctx, t));
        }
        /// <summary>
        /// Register a Func to run against any object of this PluginType immediately after it is created,
        /// but before the new object is passed back to the caller.  Unlike <see cref="OnCreation(Action{IContext,PLUGINTYPE})">OnCreation()</see>,
        /// EnrichWith() gives the the ability to return a different object.  Use this method for runtime AOP
        /// scenarios or to return a decorator.
        /// </summary>
        /// <param name="handler"></param>
        /// <returns></returns>
        public CreatePluginFamilyExpression <PLUGINTYPE> EnrichAllWith(ContextEnrichmentHandler <PLUGINTYPE> handler)
        {
            _children.Add(
                graph =>
            {
                var interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE),
                                                            (c, o) => handler(c, (PLUGINTYPE)o));
                graph.InterceptorLibrary.AddInterceptor(interceptor);
            });

            return(this);
        }
Esempio n. 8
0
        public DecoratedInstance <T> With <TDecorator>()
        {
            ContextEnrichmentHandler <T> decorator = (ctx, t) =>
            {
                var pluginType = ctx.BuildStack.Current.RequestedType;
                ctx.RegisterDefault(pluginType, t);

                return(ctx.GetInstance <TDecorator>());
            };

            _instance.EnrichWith(decorator);

            return(new DecoratedInstance <T>(_instance, decorator));
        }
Esempio n. 9
0
            public DecoratedInstance <T> AndThen <TDecorator>()
            {
                var previous = _decorator;
                ContextEnrichmentHandler <T> newDecorator = (ctx, t) =>
                {
                    var pluginType    = ctx.BuildStack.Current.RequestedType;
                    var innerInstance = previous(ctx, t);
                    ctx.RegisterDefault(pluginType, innerInstance);

                    return(ctx.GetInstance <TDecorator>());
                };

                _instance.EnrichWith(newDecorator);
                _decorator = newDecorator;

                return(this);
            }
Esempio n. 10
0
        public DecoratedInstance <TTarget> With <TDecorator>()
        {
            ContextEnrichmentHandler <TTarget> decorator = (ctx, t) =>
            {
                //var pluginType = ctx.BuildStack.Current.RequestedType;
                var pluginType = ctx.BuildStack.Current != null
                                                         ? ctx.BuildStack.Current.RequestedType
                                                         : typeof(TTarget);

                ctx.RegisterDefault(pluginType, t);

                return(ctx.GetInstance <TDecorator>());
            };

            _decorateCommand(decorator);

            return(new DecoratedInstance <TTarget>(_decorateCommand, decorator));
        }
Esempio n. 11
0
 public DecoratedInstance(Action <ContextEnrichmentHandler <TTarget> > decorateCommand, ContextEnrichmentHandler <TTarget> decorator)
 {
     _decorateCommand = decorateCommand;
     _decorator       = decorator;
 }
Esempio n. 12
0
 public DecoratedInstance(SmartInstance <TTarget> instance, ContextEnrichmentHandler <TTarget> decorator)
 {
     _instance  = instance;
     _decorator = decorator;
 }
Esempio n. 13
0
 public EnrichmentInterceptor(ContextEnrichmentHandler <T> handler)
 {
     _handler = handler;
 }