Esempio n. 1
0
        public static IAddRemotiatrOptions AddJsonSerializer(this IAddRemotiatrOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Services.TryAddScoped <IMessageSerializer>(x =>
            {
                var messageHostInfoLookup = x.GetRequiredService <IMessageHostInfoLookup>();

                var allowedMessageTypes = _allowedMessageTypesCache.GetValue(messageHostInfoLookup, x =>
                {
                    var requestTypes = x
                                       .SelectMany(x => x.Value.MessageInfos)
                                       .Select(x => x.Key)
                                       .ToArray();

                    var responseTypes = requestTypes.Select(x =>
                                                            x.GetInterfaces().FirstOrDefault(y => y.IsGenericType && y.GetGenericTypeDefinition() == typeof(IRequest <>)))
                                        .Where(x => x != null)
                                        .Select(x => x.GetGenericArguments().First())
                                        .ToArray();

                    return(requestTypes.Concat(responseTypes).ToHashSet());
                });

                return(new DefaultJsonMessageSerializer(allowedMessageTypes));
            });

            return(options);
        }
        private static IAddRemotiatrOptions Configure(IAddRemotiatrOptions options, IEnumerable <Assembly> assemblies, ServiceLifetime serviceLifetime)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }
            if (!Enum.IsDefined(typeof(ServiceLifetime), serviceLifetime))
            {
                throw new InvalidEnumArgumentException(nameof(serviceLifetime), (int)serviceLifetime, typeof(ServiceLifetime));
            }

            options.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            options.Services.Add(new ServiceDescriptor(
                                     typeof(IPipelineBehavior <,>),
                                     typeof(ValidationPipelineBehavior <,>),
                                     serviceLifetime
                                     ));

            options.Services.AddValidatorsFromAssemblies(assemblies, serviceLifetime);

            return(options);
        }
Esempio n. 3
0
 public static IAddRemotiatrOptions AddHost <TMessageSerializer>(
     this IAddRemotiatrOptions options,
     Uri rootUri,
     Func <Type, Uri> pathLocator,
     params Assembly[] assemblies
     )
     where TMessageSerializer : IMessageSerializer
 => options.AddHost(rootUri, pathLocator, typeof(TMessageSerializer), assemblies);
Esempio n. 4
0
        public static IAddRemotiatrOptions AddHttpMessageTransport(this IAddRemotiatrOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Services.TryAddScoped <IMessageTransport, DefaultHttpMessageTransport>();

            return(options);
        }
Esempio n. 5
0
        private static void Configure(IAddRemotiatrOptions options, IEnumerable <Assembly> assemblies, ServiceLifetime lifetime)
        {
            options.Services.TryAddScoped <IValidationErrorsAccessor, DefaultValidationErrorsAccessor>();

            options.Services.Add(new ServiceDescriptor(
                                     typeof(IPipelineBehavior <,>),
                                     typeof(ValidationPipelineBehavior <,>),
                                     lifetime)
                                 );

            options.Services.AddValidatorsFromAssemblies(assemblies, lifetime);
        }
        public static IAddRemotiatrOptions AddFluentValidation(this IAddRemotiatrOptions options, params Assembly[] assemblies)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }

            Configure(options, assemblies, ServiceLifetime.Transient);

            return(options);
        }
        public static IAddRemotiatrOptions AddFluentValidation(this IAddRemotiatrOptions options, params Type[] assemblyTypeMarkers)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (assemblyTypeMarkers == null)
            {
                throw new ArgumentNullException(nameof(assemblyTypeMarkers));
            }

            Configure(options, assemblyTypeMarkers.Select(x => x.Assembly), ServiceLifetime.Transient);

            return(options);
        }
        public static IAddRemotiatrOptions AddFluentValidation(this IAddRemotiatrOptions options, IEnumerable <Assembly> assemblies, ServiceLifetime serviceLifetime)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }
            if (!Enum.IsDefined(typeof(ServiceLifetime), serviceLifetime))
            {
                throw new InvalidEnumArgumentException(nameof(serviceLifetime), (int)serviceLifetime, typeof(ServiceLifetime));
            }

            Configure(options, assemblies, serviceLifetime);

            return(options);
        }
 public static IAddRemotiatrOptions WithMediatorImplementationType <TMediator>(this IAddRemotiatrOptions addRemotiatrOptions)
     where TMediator : IMediator =>
 addRemotiatrOptions?.WithMediatorImplementationType(typeof(TMediator)) ?? throw new ArgumentNullException(nameof(addRemotiatrOptions));
 public static IAddRemotiatrOptions AsTransient(this IAddRemotiatrOptions addRemotiatrOptions) =>
 addRemotiatrOptions?.WithMediatorLifetime(ServiceLifetime.Transient) ?? throw new ArgumentNullException(nameof(addRemotiatrOptions));
Esempio n. 11
0
 public static IAddRemotiatrOptions AddHost(this IAddRemotiatrOptions options, Uri rootUri, params Assembly[] assemblies) =>
 options.AddHost(rootUri, x => new Uri("remotiatr", UriKind.Relative), typeof(IMessageSerializer), assemblies);
Esempio n. 12
0
 public static IAddRemotiatrOptions ConfigureMediator <TMediator>(this IAddRemotiatrOptions options, ServiceLifetime serviceLifetime) where TMediator : IMediator =>
 options.ConfigureMediator(typeof(TMediator), serviceLifetime);