Ejemplo n.º 1
0
        /// <summary>
        ///     Registers this instance.
        /// </summary>
        /// <exception cref="ProxyInitializationException"></exception>
        private void Register()
        {
            try
            {
                if (!ObjectHelper.IsNull(_instance))
                {
                    return;
                }

                _states = TypeFactory.CreateInstance <StateInterceptorCollection>();

                var stateIntercepors = Callbacks.Keys.Select(key => TypeFactory.CreateInstanceWithParameters <StateInterceptor>(key, Callbacks[key]));

                stateIntercepors.ForEach(stateInterceptor => _states.Add(stateInterceptor));

                _context = TypeFactory.CreateInstanceWithParameters <ContextInterceptor>(_states);

                _instance = _proxyFactory.Create(_target, _context, ImplementedTypes.ToArray());

                Container.RegisterInstance(ServiceType, _instance, Tag);
            }
            catch (Exception exception)
            {
                throw new ProxyInitializationException(
                          string.Format("Unable to create a proxy instance of a '{0}' type: {1}", ServiceType.Name,
                                        exception.Message),
                          exception);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContextInterceptor" /> class.
        /// </summary>
        /// <param name="stateInterceptors">The state interceptors.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="stateInterceptors"/> is <c>null</c>.</exception>
        public ContextInterceptor(IList<StateInterceptor> stateInterceptors)
        {
            Argument.IsNotNull(() => stateInterceptors);

            StateInterceptorCollection = new StateInterceptorCollection(stateInterceptors);
        }