Esempio n. 1
0
        /// <inheritdoc/>
        public void ProvideMiddleware(Service service, IComponentRegistryServices availableServices, IResolvePipelineBuilder pipelineBuilder)
        {
            if (service is IServiceWithType swt)
            {
                var closedDecoratorService = new DecoratorService(swt.ServiceType, _decoratorService.Condition);

                // Try to bind to the service.
                if (OpenGenericServiceBinder.TryBindOpenGenericTypedService(closedDecoratorService, _registrationData.Services, _activatorData.ImplementationType, out var constructedImplementationType, out var services))
                {
                    // Create a new closed-generic registration.
                    var registration = new ComponentRegistration(
                        Guid.NewGuid(),
                        new ReflectionActivator(constructedImplementationType, _activatorData.ConstructorFinder, _activatorData.ConstructorSelector, _activatorData.ConfiguredParameters, _activatorData.ConfiguredProperties),
                        _registrationData.Lifetime,
                        _registrationData.Sharing,
                        _registrationData.Ownership,
                        services,
                        _registrationData.Metadata);

                    // Build the resolve pipeline so we can invoke it.
                    registration.BuildResolvePipeline(availableServices);

                    // Add our closed decorator middleware to the pipeline.
                    pipelineBuilder.Use(new DecoratorMiddleware(closedDecoratorService, registration), MiddlewareInsertionMode.StartOfPhase);
                }
            }
        }