Pendent
Inheritance: System.MarshalByRefObject
        /// <summary>
        /// Tries to obtain transaction configuration based on 
        /// the component configuration or (if not available) check
        /// for the attributes.
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        /// <param name="model">The model.</param>
        public override void ProcessModel(IKernel kernel, ComponentModel model)
        {
            if (metaStore == null)
            {
                metaStore = (TransactionMetaInfoStore) kernel[typeof(TransactionMetaInfoStore)];
            }

            if (IsMarkedWithTransactional(model.Configuration))
            {
                base.ProcessModel(kernel, model);
            }
            else
            {
                AssertThereNoTransactionOnConfig(model);

                ConfigureBasedOnAttributes(model);
            }

            Validate(model, metaStore);

            AddTransactionInterceptorIfIsTransactional(model, metaStore);
        }
Esempio n. 2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TransactionInterceptor"/> class.
		/// </summary>
		/// <param name="kernel">The kernel.</param>
		/// <param name="infoStore">The info store.</param>
		public TransactionInterceptor(IKernel kernel, TransactionMetaInfoStore infoStore)
		{
            this.kernel = kernel;
			this.infoStore = infoStore;
		}
        /// <summary>
        /// Validates the type is OK to generate a proxy.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="store">The store.</param>
        private void Validate(ComponentModel model, TransactionMetaInfoStore store)
        {
            if (model.Service == null || model.Service.IsInterface)
            {
                return;
            }

            TransactionMetaInfo meta = store.GetMetaFor(model.Implementation);

            if (meta == null)
            {
                return;
            }

            ArrayList problematicMethods = new ArrayList();

            foreach(MethodInfo method in meta.Methods)
            {
                if (!method.IsVirtual)
                {
                    problematicMethods.Add(method.Name);
                }
            }

            if (problematicMethods.Count != 0)
            {
                String[] methodNames = (String[]) problematicMethods.ToArray(typeof(String));

                String message = String.Format("The class {0} wants to use transaction interception, " +
                                               "however the methods must be marked as virtual in order to do so. Please correct " +
                                               "the following methods: {1}", model.Implementation.FullName,
                                               String.Join(", ", methodNames));

                throw new FacilityException(message);
            }
        }
        /// <summary>
        /// Associates the transaction interceptor with the ComponentModel.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="store">The meta information store.</param>
        private static void AddTransactionInterceptorIfIsTransactional(ComponentModel model,
		                                                               TransactionMetaInfoStore store)
        {
            TransactionMetaInfo meta = store.GetMetaFor(model.Implementation);

            if (meta == null)
            {
                return;
            }

            model.Dependencies.Add(
                new DependencyModel(DependencyType.Service, null, typeof(TransactionInterceptor), false));

            model.Interceptors.AddFirst(new InterceptorReference(typeof(TransactionInterceptor)));
        }