Ejemplo n.º 1
0
        public TransactionMetaInfo CreateMetaFromType(Type implementation)
        {
            TransactionMetaInfo metaInfo = new TransactionMetaInfo();

            PopulateMetaInfoFromType(metaInfo, implementation);

            Register(implementation, metaInfo);

            return(metaInfo);
        }
        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"));
        }
Ejemplo n.º 3
0
        public TransactionMetaInfo CreateMetaFromConfig(Type implementation, IList <MethodInfo> methods, IConfiguration config)
        {
            TransactionMetaInfo metaInfo = GetMetaFor(implementation);

            if (metaInfo == null)
            {
                metaInfo = new TransactionMetaInfo();
            }

            foreach (MethodInfo method in methods)
            {
                metaInfo.Add(method, new TransactionAttribute());
            }

            Register(implementation, metaInfo);

            return(metaInfo);
        }
Ejemplo n.º 4
0
        private static void PopulateMetaInfoFromType(TransactionMetaInfo metaInfo, Type implementation)
        {
            if (implementation == typeof(object) || implementation == typeof(MarshalByRefObject))
            {
                return;
            }

            MethodInfo[] methods = implementation.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            foreach (MethodInfo method in methods)
            {
                object[] atts = method.GetCustomAttributes(typeof(TransactionAttribute), true);
                if (atts.Length != 0)
                {
                    metaInfo.Add(method, atts[0] as TransactionAttribute);
                }
            }

            PopulateMetaInfoFromType(metaInfo, implementation.BaseType);
        }
        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);
            }
        }
 /// <summary>
 /// Sets the intercepted component's ComponentModel.
 /// </summary>
 /// <param name="target">The target's ComponentModel</param>
 public void SetInterceptedComponentModel(ComponentModel target)
 {
     _metaInfo = _infoStore.GetMetaFor(target.Implementation);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets the intercepted component's ComponentModel.
 /// </summary>
 /// <param name="target">The target's ComponentModel</param>
 public void SetInterceptedComponentModel(ComponentModel target)
 {
     _metaInfo = _infoStore.GetMetaFor(target.Implementation);
 }
Ejemplo n.º 8
0
 private void Register(Type implementation, TransactionMetaInfo metaInfo)
 {
     _type2MetaInfo[implementation] = metaInfo;
 }