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);
        }
        private void Validate(ComponentModel model, TransactionMetaInfoStore store)
        {
            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);
            }
        }
        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("eventsourcing.transaction.interceptor"));
        }
Пример #4
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, ILoggerFactory loggerFactory)
 {
     this._kernel    = kernel;
     this._infoStore = infoStore;
     this._logger    = loggerFactory.Create("EventSourcing.TransactionInterceptor");
 }