Exemplo n.º 1
0
        public static void AddTypeSubscriptionIfNotExists(
            this ICollection <ISubscription> collection,
            Type subscriberType,
            TypeSubscriptionOptions options)
        {
            bool exists = collection.OfType <TypeSubscription>()
                          .Any(existingSubscription => existingSubscription.SubscribedType == subscriberType);

            if (!exists)
            {
                collection.Add(new TypeSubscription(subscriberType, options));
            }
        }
Exemplo n.º 2
0
        private SubscribedMethod GetSubscribedMethod(Type targetType, MethodInfo methodInfo)
        {
            var subscribeAttribute = methodInfo.GetCustomAttribute <SubscribeAttribute>();

            // TODO: Migrate to records
            var methodOptions = new TypeSubscriptionOptions
            {
                Filters = _options.Filters
                          .Union(methodInfo.GetCustomAttributes <MessageFilterAttribute>(false))
                          .Distinct().ToList(),
                Exclusive = subscribeAttribute?.Exclusive ?? _options.Exclusive,
                AutoSubscribeAllPublicMethods = _options.AutoSubscribeAllPublicMethods
            };

            return(new SubscribedMethod(
                       serviceProvider => serviceProvider.GetRequiredService(targetType),
                       methodInfo,
                       methodOptions));
        }
Exemplo n.º 3
0
 public TypeSubscription(Type subscribedType, TypeSubscriptionOptions options)
 {
     SubscribedType = Check.NotNull(subscribedType, nameof(subscribedType));
     _options       = Check.NotNull(options, nameof(options));
 }