public static ComponentRegistration <T> WithRepositoryAccess <T>(this ComponentRegistration <T> registration, string localBoundedContext) where T : class
 {
     return(registration.ExtendedProperties(new
     {
         DependsOnBoundedContextRepository = localBoundedContext,
     }));
 }
Example #2
0
        public static ComponentRegistration <TComponent> ListensToEvent <TComponent>(
            this ComponentRegistration <TComponent> registration,
            Type eventType,
            MethodInfo handleMethod
            ) where TComponent : class
        {
            Debug.Assert(handleMethod != null);
            Debug.Assert(handleMethod.ReturnType == typeof(void));
            Debug.Assert(handleMethod.GetParameters().Single().ParameterType == eventType);

            var /*Action<TListener, TEvent>*/ @delegate = (Delegate)(typeof(ComponentRegistrationEx).
                                                                     GetMethod("CreateInvoker", BindingFlags.Static | BindingFlags.NonPublic).
                                                                     MakeGenericMethod(typeof(TComponent), eventType).
                                                                     Invoke(null, new object[] { handleMethod })
                                                                     );

            registration.ExtendedProperties(Property.
                                            ForKey(GrayMatterFacility.CreateExtendedPropertyKey(
                                                       eventType, handleMethod.ReflectedType.ToString(),
                                                       handleMethod.Name
                                                       )).
                                            Eq(new Wiring(eventType, @delegate))
                                            );

            return(registration);
        }
Example #3
0
 public static ComponentRegistration <T> WithStartablePriorityLowest <T>(this ComponentRegistration <T> registration)
     where T : class
 {
     registration.ExtendedProperties(
         new Property(JarvisStartableFacility.PriorityExtendedPropertyKey,
                      JarvisStartableFacility.Priorities.Lowest));
     return(registration);
 }
 public static ComponentRegistration <T> AsProcess <T>(this ComponentRegistration <T> registration, string localBoundedContext) where T : class
 {
     return(registration.ExtendedProperties(new
     {
         ProcessFor = localBoundedContext,
         IsProcess = true
     }));
 }
 public static ComponentRegistration <T> AsSaga <T>(this ComponentRegistration <T> registration, params string[] boundedContexts) where T : class
 {
     return(registration.ExtendedProperties(new
     {
         ListenedBoundContexts = boundedContexts,
         IsSaga = true
     }));
 }
 public static ComponentRegistration <T> AsCommandsHandler <T>(this ComponentRegistration <T> registration, string localBoundedContext) where T : class
 {
     return(registration.ExtendedProperties(new
     {
         CommandsHandlerFor = localBoundedContext,
         IsCommandsHandler = true
     }));
 }
Example #7
0
        public static IRegistration HandleMessagesAuto <THandler>(this ComponentRegistration <THandler> registration)
            where THandler : class
        {
            var typeValidator = new GenericTypeValidation();
            var messageType   = typeValidator.GetGenericParameter(registration.Implementation, typeof(IRabbitMessageHandler <>));

            registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.MessageTypeKey).Eq(messageType));

            if (messageType.IsGenericType && messageType.GetGenericTypeDefinition() == typeof(IEnumerable <>))
            {
                //Batch messaging

                registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.IsEnumerableMessageType).Eq(true));

                var config = registration.Implementation.GetAttribute <RabbitMessageBatchHandlerAttribute>().GetConfig();
                registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.QueueNameKey).Eq(config));

                var realMessageType = messageType.GetGenericArguments()[0];
                registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.MessageTypeKey).Eq(realMessageType));
            }
            else
            {
                registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.IsEnumerableMessageType).Eq(false));

                var config = registration.Implementation.GetAttribute <RabbitMessageHandlerAttribute>().GetConfig();
                registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.QueueNameKey).Eq(config));

                registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.MessageTypeKey).Eq(messageType));
            }

            return(registration);
        }
Example #8
0
        /// <summary>
        /// Indicates that the specified component should be automatically implemented from
        /// the config.
        /// </summary>
        /// <typeparam name="T">The type of the interface to implement.</typeparam>
        /// <param name="registration">The registration.</param>
        /// <param name="configAction">Allows you to customize how the settings interface is implemented.</param>
        /// <returns>The registration.</returns>
        public static ComponentRegistration <T> FromAppConfig <T>(this ComponentRegistration <T> registration,
                                                                  Action <IConfigConfiguration <T> > configAction = null)
            where T : class
        {
            registration.Interceptors <AppConfigInterceptor>();

            if (configAction != null)
            {
                var configuration = new ConfigConfiguration <T>();
                configAction(configuration);

                registration.ExtendedProperties(new Property(AppConfigInterceptor.ComputedPropertiesKey,
                                                             configuration.ComputedDictionary));
                registration.ExtendedProperties(new Property(AppConfigInterceptor.PrefixKey, configuration.Prefix));
            }

            return(registration);
        }
Example #9
0
        public ComponentRegistration <TListener> With(Action <TListener, TEvent> handler)
        {
            _componentRegistration.ExtendedProperties(Property.
                                                      ForKey(GrayMatterFacility.CreateExtendedPropertyKey(typeof(TEvent), null, null)).
                                                      Eq(new Wiring(typeof(TEvent), handler))
                                                      );

            return(_componentRegistration);
        }
Example #10
0
 public static ComponentRegistration <TService> Replace <TService>(
     this ComponentRegistration <TService> @this, string componentName)
     where TService : class
 {
     return(@this.ExtendedProperties(new Property(PropertyKey.Replacement, new Replacement
     {
         Name = componentName
     })));
 }
 public static ComponentRegistration <T> AsProjection <T>(this ComponentRegistration <T> registration, string boundContext, string projectedBoundContext) where T : class
 {
     return(registration.ExtendedProperties(new
     {
         IsProjection = true,
         ProjectedBoundContext = projectedBoundContext,
         BoundContext = boundContext
     }));
 }
        private ComponentRegistration <A> AddResolveExtensions(ComponentRegistration <A> componentRegistration,
                                                               params IResolveExtension[] items)
        {
            var resolveExtensions = new List <IResolveExtension>();

            foreach (var item in items.Distinct())
            {
                resolveExtensions.Add(item);
            }
            return(componentRegistration.ExtendedProperties(Property.ForKey("Castle.ResolveExtensions").Eq(resolveExtensions)));
        }
        /// <summary>
        /// Defines the specified component registration as overridable.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="registration">The registration.</param>
        /// <returns>The same component registration.</returns>
        public static ComponentRegistration <T> Overridable <T>(this ComponentRegistration <T> registration)
            where T : class
        {
            registration.ExtendedProperties
            (
                Property.ForKey(OVERRIDABLE_OVERRIDABLE_REGISTRATION)
                .Eq(true)
            );

            return(registration);
        }
        private ComponentRegistration <TComponent> WithReleaseExtensions <TComponent>(
            ComponentRegistration <TComponent> componentRegistration, params IReleaseExtension[] items)
            where TComponent : class
        {
            var releaseExtensions = new List <IReleaseExtension>();

            foreach (var item in items.Distinct())
            {
                releaseExtensions.Add(item);
            }
            return(componentRegistration.ExtendedProperties(Property.ForKey("Castle.ReleaseExtensions").Eq(releaseExtensions)));
        }
Example #15
0
        public static IRegistration MessageService <TMessageService>(this ComponentRegistration <TMessageService> registration) where TMessageService : class
        {
            var rabbitMessageServiceAttribute = registration.Implementation.GetAttribute <RabbitMessageServiceAttribute>();

            if (rabbitMessageServiceAttribute == null)
            {
                throw new Exception("");
            }

            registration.ExtendedProperties(Property.ForKey(RxRabbitClientFacility.IsService).Eq(true));
            return(registration);
        }
Example #16
0
        public static List <IResolveExtension> GetResolveExtensions <TService>(this ComponentRegistration <TService> extended)
            where TService : class
        {
            if (!ResolveExtensionsDictionary.ContainsKey(extended))
            {
                var resolveExtensions = new List <IResolveExtension>();
                var property          = Property.ForKey(PropertyKey).Eq(resolveExtensions);
                extended.ExtendedProperties(property);
                ResolveExtensionsDictionary.Add(extended, resolveExtensions);
            }

            var result = ResolveExtensionsDictionary[extended];

            return(result);
        }
Example #17
0
        public ComponentRegistration <TService> Build()
        {
            if (string.IsNullOrEmpty(ServiceTypeName))
            {
                throw new ComponentRegistrationException("Stateful ServiceTypeName cannot be null or empty");
            }

            if (StateManagerConfiguration != null)
            {
                _registration.ExtendedProperties(
                    Property
                    .ForKey <ReliableStateManagerConfiguration>()
                    .Eq(StateManagerConfiguration));
            }

            return(_registration
                   .AddAttributeDescriptor(FacilityConstants.StatefulServiceKey, bool.TrueString)
                   .AddAttributeDescriptor(FacilityConstants.ServiceTypeNameKey, ServiceTypeName));
        }
Example #18
0
        public static ComponentRegistration <TService> Replace <TService>(
            this ComponentRegistration <TService> @this, Type[] serviceTypes, params Type[] implementationTypes)
            where TService : class
        {
            foreach (var implementationType in implementationTypes)
            {
                foreach (var serviceType in serviceTypes)
                {
                    if (!serviceType.IsAssignableFrom(implementationType))
                    {
                        throw new ArgumentException(
                                  $"Implementation {implementationType.FullName} does not implement {serviceType.FullName}");
                    }
                }
            }

            return(@this.ExtendedProperties(new Property(PropertyKey.Replacement, new Replacement
            {
                Services = serviceTypes,
                Implementations = implementationTypes
            })));
        }
Example #19
0
 public static ComponentRegistration <T> DependsOnBundle <T>(this ComponentRegistration <T> r, string bundleName, string jsonPath, params string[] parameters) where T : class
 {
     return(r.ExtendedProperties(new { dependsOnBundle = bundleName, jsonPath, bundleParameters = parameters }));
 }
 private void ConfigureAspect(ComponentRegistration componentRegistration)
 {
     componentRegistration.Forward <IInterceptor>();
     componentRegistration.ExtendedProperties(genericImplementationMatchingStrategyProperty);
 }
Example #21
0
 public static ComponentRegistration <TService> ResolvableIf <TService>(
     this ComponentRegistration <TService> @this, Func <bool> predicate) where TService : class
 {
     return(@this.ExtendedProperties(new Property(PropertyKey.Predicate, predicate)));
 }
Example #22
0
 public static ComponentRegistration <TService> MatchLifestyleTo <TService>(
     this ComponentRegistration <TService> registration, string otherComponentName)
 {
     return(registration.ExtendedProperties(Property.ForKey(key).Eq(otherComponentName))
            .Interceptors <UseDifferentTargetInterceptor>());
 }
 public static ComponentRegistration <T> AsMessageHandler <T>(this ComponentRegistration <T> r, params string[] endpoints)
     where T : class
 {
     return(r.ExtendedProperties(new { MessageHandlerFor = endpoints }).WithEndpoints(endpoints.ToDictionary(name => name)));
 }