Exemplo n.º 1
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>(EnrichmentHandler <TPluginType> handler)
        {
            var interceptor = new EnrichmentInterceptor <TPluginType>((c, o) => handler(o));

            Interceptor = interceptor;

            return(this);
        }
Exemplo 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 <PLUGINTYPE>(EnrichmentHandler <PLUGINTYPE> handler)
        {
            var interceptor = new EnrichmentInterceptor <PLUGINTYPE>((c, o) => handler(o));

            Interceptor = interceptor;

            return(this);
        }
Exemplo 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>
        /// <typeparam name="TYPE"></typeparam>
        /// <param name="handler"></param>
        /// <returns></returns>
        public T EnrichWith <TYPE>(EnrichmentHandler <TYPE> handler)
        {
            var interceptor = new EnrichmentInterceptor <TYPE>((c, o) => handler(o));

            Interceptor = interceptor;

            return(thisInstance);
        }
Exemplo 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>(EnrichmentHandler <T> handler)
        {
            var interceptor = new EnrichmentInterceptor <T>((c, o) => handler(o));

            Interceptor = interceptor;

            return(this);
        }
        /// <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{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(EnrichmentHandler <PLUGINTYPE> handler)
        {
            _children.Add(
                graph =>
            {
                Func <IContext, object, object> function = (context, target) => handler((PLUGINTYPE)target);

                var interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function);
                graph.InterceptorLibrary.AddInterceptor(interceptor);
            });

            return(this);
        }