Ejemplo n.º 1
0
        public MediatorHandlerTests()
        {
            services = new ServiceContainer();

            ServiceRegistrar.AddMediatRClasses(services, new[] { Assembly.GetExecutingAssembly() });
            ServiceRegistrar.AddRequiredServices(services);

            mediator = services.GetInstance <IMediator>();
        }
        public void AddRequiredServices_WhenCalled_ShouldContainExpectedInstances()
        {
            ServiceRegistrar.AddMediatRClasses(services, assemblies);
            ServiceRegistrar.AddRequiredServices(services);

            services.GetInstance <IMediator>().ShouldBeOfType <Mediator>();
            services.GetInstance <ISender>().ShouldBeOfType <Mediator>();
            services.GetInstance <IPublisher>().ShouldBeOfType <Mediator>();
            services.AvailableServices.Where(x => x.ServiceType == typeof(INotificationHandler <PingNotification>)).Count().ShouldBe(3);
        }
Ejemplo n.º 3
0
        public static IServiceCollection AddMediatRCore(this IServiceCollection services, Action <MediatRServiceConfiguration> configuration = null)
        {
            var serviceConfig = new MediatRServiceConfiguration();

            configuration?.Invoke(serviceConfig);

            ServiceRegistrar.AddRequiredServices(services, serviceConfig);

            return(services);
        }
        public static void AddLeeliteCore(this IServiceCollection services)
        {
            services.AddMapper();

            var serviceConfig = new MediatRServiceConfiguration();

            serviceConfig.AsScoped();

            ServiceRegistrar.AddRequiredServices(services, serviceConfig);
        }
Ejemplo n.º 5
0
        private static void AddDefaultServices(AddRemotiatrOptions options)
        {
            options.Services.TryAddScoped <IApplicationServiceProviderAccessor, ApplicationServiceProviderAccessor>();

            options.Services.TryAddTransient(typeof(IApplicationService <>), typeof(ApplicationService <>));

            options.Services.AddScoped <IMessageMetadata, MessageMetadata>();

            options.Services.AddSingleton <IMessageHostInfoLookup, MessageHostInfoLookup>();

            ServiceRegistrar.AddRequiredServices(options.Services, new MediatRServiceConfiguration());
        }
Ejemplo n.º 6
0
 public static IServiceCollection AddJsonRpcMediatR(this IServiceCollection services, IEnumerable <Assembly> assemblies)
 {
     ServiceRegistrar.AddRequiredServices(services, new MediatRServiceConfiguration());
     ServiceRegistrar.AddMediatRClasses(services, assemblies);
     services.AddScoped <IRequestContext, RequestContext>();
     services.RemoveAll <ServiceFactory>();
     services.AddScoped <ServiceFactory>(
         serviceProvider => {
         return(serviceType => GetHandler(serviceProvider, serviceType));
     }
         );
     return(services);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Registers handlers and mediator types from the specified assemblies
        /// </summary>
        /// <param name="services">Service collection</param>
        /// <param name="assemblies">Assemblies to scan</param>
        /// <param name="configuration">The action used to configure the options</param>
        /// <returns>Service collection</returns>
        public static IServiceCollection AddMediatR(this IServiceCollection services, IEnumerable <Assembly> assemblies, Action <MediatRServiceConfiguration> configuration)
        {
            if (!assemblies.Any())
            {
                throw new ArgumentException("No assemblies found to scan. Supply at least one assembly to scan for handlers.");
            }
            var serviceConfig = new MediatRServiceConfiguration();

            configuration?.Invoke(serviceConfig);

            ServiceRegistrar.AddRequiredServices(services, serviceConfig);

            ServiceRegistrar.AddMediatRClasses(services, assemblies);

            return(services);
        }
        /// <summary>
        /// Registers the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="services">The services.</param>
        public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services)
        {
            var serviceConfig = context.GetOrAdd(() => new MediatRServiceConfiguration());

            if (services.Any(z => z.ServiceType == typeof(IMediator)))
            {
                return;
            }

            context.Set(serviceConfig);
            var assemblies = context.AssemblyCandidateFinder
                             .GetCandidateAssemblies(nameof(MediatR)).ToArray();

            ServiceRegistrar.AddRequiredServices(services, serviceConfig);
            ServiceRegistrar.AddMediatRClasses(services, assemblies);
        }