Example #1
0
        /// <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)
        {
            TransactionMetaInfo meta;
            var problematicMethods = new List <string>();

            foreach (var service in model.Services)
            {
                if (service == null ||
                    service.IsInterface ||
                    (meta = store.GetMetaFor(model.Implementation)) == null ||
                    (problematicMethods = (
                         from method in meta.Methods
                         where !method.IsVirtual
                         select method.Name
                         ).ToList())
                    .Count == 0)
                {
                    return;
                }
            }

            throw new FacilityException(
                      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(", ", problematicMethods.ToArray())));
        }
Example #2
0
        /// <summary>
        /// Associates the transaction interceptor with the ComponentModel.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="store">The meta information store.</param>
        private void AddTransactionInterceptorIfIsTransactional(ComponentModel model,
                                                                TransactionMetaInfoStore store)
        {
            TransactionMetaInfo meta = store.GetMetaFor(model.Implementation);

            if (meta == null)
            {
                return;
            }

            model.Dependencies.Add(
                new DependencyModel(this.ObtainNodeName(), typeof(TransactionInterceptor), false));

            model.Interceptors.AddFirst(new InterceptorReference(typeof(TransactionInterceptor)));
        }
        /// <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(null, typeof(TransactionInterceptor), false));

            //model.Interceptors.AddFirst(new InterceptorReference(typeof(TransactionInterceptor)));
            model.Interceptors.AddFirst(new InterceptorReference("transaction.interceptor"));//必须声明此名称,否则注册此拦截器时不可Named()
        }
Example #4
0
        /// <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 = kernel.Resolve <TransactionMetaInfoStore>();
            }

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

                ConfigureBasedOnAttributes(model);
            }

            Validate(model, metaStore);

            AddTransactionInterceptorIfIsTransactional(model, metaStore);
        }
		/// <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);
		}
        /// <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)
        {
            //HACK:model.Service->model.Services
            if (model.Services.Count() == 0 || model.Services.All(o => o.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)));
		}
		/// <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(null, typeof(TransactionInterceptor), false));

            //model.Interceptors.AddFirst(new InterceptorReference(typeof(TransactionInterceptor)));
            model.Interceptors.AddFirst(new InterceptorReference("transaction.interceptor"));//�������������ƣ�����ע���������ʱ����Named()
        }
		/// <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)
		{
			TransactionMetaInfo meta;
			var problematicMethods = new List<string>();

			foreach (var service in model.Services)
			{
				if (service == null
				    || service.IsInterface
				    || (meta = store.GetMetaFor(model.Implementation)) == null
				    || (problematicMethods = (
				                             	from method in meta.Methods
				                             	where !method.IsVirtual
				                             	select method.Name
				                             ).ToList())
				       	.Count == 0)
				{
					return;
				}
			}

			throw new FacilityException(
				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(", ", problematicMethods.ToArray())));
		}
Example #12
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;
 }