public void ShouldContainDefaultSettingsAfterCreation()
    {
        // Arrange
        var config = new MediatRSimpleInjectorConfiguration();

        // Assert
        using (new AssertionScope())
        {
            config.Lifestyle.Should().Be(Lifestyle.Singleton);
            config.MediatorImplementationType.Should().Be(typeof(Mediator));
            config.MediatorInstanceCreator.Should().NotBeNull();
            config.MediatorInstanceCreator().Should().BeNull();
            config.RequestPreProcessorBehaviorEnabled.Should().BeFalse();
            config.RequestPostProcessorBehaviorEnabled.Should().BeFalse();
            config.RequestExceptionProcessorBehaviorEnabled.Should().BeFalse();
            config.RequestExceptionActionProcessorBehaviorEnabled.Should().BeFalse();
            config.AssembliesToScan.Should().BeEmpty();
            config.PipelineBehaviorTypes.Should().BeEmpty();
        }
    }
Exemple #2
0
    internal static Container SetupContainer(
        this Container container,
        MediatRSimpleInjectorConfiguration serviceConfig)
    {
        var uniqueAssemblies = serviceConfig.AssembliesToScan.Distinct().ToArray();
        var allAssemblies    = new List <Assembly> {
            typeof(IMediator).GetTypeInfo().Assembly
        };

        allAssemblies.AddRange(uniqueAssemblies);

        var customMediatorInstance = serviceConfig.MediatorInstanceCreator();

        if (customMediatorInstance is null)
        {
            container.Register(
                typeof(IMediator),
                serviceConfig.MediatorImplementationType,
                serviceConfig.Lifestyle);
        }
        else
        {
            container.Register(
                () => customMediatorInstance,
                serviceConfig.Lifestyle);
        }

        container.Register(typeof(IRequestHandler <,>), allAssemblies);
        container.Register(typeof(IStreamRequestHandler <,>), allAssemblies);
        RegisterNotifications(container, uniqueAssemblies);
        RegisterBehaviors(container, serviceConfig, uniqueAssemblies);

        container.Register(() => new ServiceFactory(container.GetInstance), Lifestyle.Singleton);

        return(container);
    }