public void Should_Register_Multiple_Instances_When_AddIfAlreadyExists_Is_True()
            {
                // Arrange
                var services    = new ServiceCollection();
                var resolutions = new[]
                {
                    new ConcreteRegistration
                    {
                        InterfaceType = typeof(IClosedInterface)
                    },
                    new ConcreteRegistration
                    {
                        InterfaceType      = typeof(IClosedInterface),
                        AddIfAlreadyExists = true
                    }
                };

                // Act
                AssemblyScanning.RegisterServices(services, new[] { Assembly }, resolutions);

                // Assert
                var registrations = services.BuildServiceProvider().GetServices <IClosedInterface>()
                                    .ToArray();

                registrations.Length.ShouldBe(2);
            }
            public void Should_Only_Register_One_Instance_When_AddIfAlreadyExists_Is_False()
            {
                // Arrange
                var services    = new ServiceCollection();
                var resolutions = new[]
                {
                    new ConcreteRegistration
                    {
                        InterfaceType = typeof(IOpenSingularInterface <>)
                    },
                    new ConcreteRegistration
                    {
                        InterfaceType = typeof(IOpenSingularInterface <>)
                    }
                };

                // Act
                AssemblyScanning.RegisterServices(services, new[] { Assembly }, resolutions);

                // Assert
                var registrations = services.BuildServiceProvider().GetServices <IOpenSingularInterface <string> >()
                                    .ToArray();

                registrations.Length.ShouldBe(1);
            }
Beispiel #3
0
        public static IServiceCollection AddCommandValidators(this IServiceCollection services, params Assembly[] validatorAssemblies)
        {
            AssemblyScanning.RegisterServices(services, validatorAssemblies, new[]
            {
                new ConcreteRegistration
                {
                    InterfaceType      = typeof(ICommandValidator <>),
                    AddIfAlreadyExists = true
                }
            });

            return(services);
        }
            public void Should_Register_ClosedClass_Against_IClosedInterface_Successfully()
            {
                // Arrange
                var services    = new ServiceCollection();
                var resolutions = new[]
                {
                    new ConcreteRegistration
                    {
                        InterfaceType = typeof(IClosedInterface)
                    }
                };

                // Act
                AssemblyScanning.RegisterServices(services, new [] { Assembly }, resolutions);

                // Assert
                services.BuildServiceProvider().GetRequiredService <IClosedInterface>().ShouldBeOfType <ClosedClass>();
            }
Beispiel #5
0
 public static IServiceCollection AddMediatRWithAssemblyScanning(this IServiceCollection services) =>
 services.AddMediatR(assemblies: AssemblyScanning.GetAssemblies());