Beispiel #1
0
        /// <inheritdoc />
        public ITapetiConfigBuilder Use(ITapetiExtension extension)
        {
            if (DependencyResolver is IDependencyContainer container)
            {
                extension.RegisterDefaults(container);
            }

            var configInstance = GetConfig();

            var middlewareBundle = extension.GetMiddleware(DependencyResolver);

            if (middlewareBundle != null)
            {
                foreach (var middleware in middlewareBundle)
                {
                    switch (middleware)
                    {
                    case IControllerBindingMiddleware bindingExtension:
                        Use(bindingExtension);
                        break;

                    case IMessageMiddleware messageExtension:
                        configInstance.Use(messageExtension);
                        break;

                    case IPublishMiddleware publishExtension:
                        configInstance.Use(publishExtension);
                        break;

                    default:
                        throw new ArgumentException(
                                  $"Unsupported middleware implementation: {(middleware == null ? "null" : middleware.GetType().Name)}");
                    }
                }
            }

            var bindingBundle = (extension as ITapetiExtensionBinding)?.GetBindings(DependencyResolver);

            if (bindingBundle == null)
            {
                return(this);
            }

            foreach (var binding in bindingBundle)
            {
                config.RegisterBinding(binding);
            }

            return(this);
        }
        public TapetiConfig Use(ITapetiExtension extension)
        {
            var container = dependencyResolver as IDependencyContainer;

            if (container != null)
            {
                extension.RegisterDefaults(container);
            }

            var middlewareBundle = extension.GetMiddleware(dependencyResolver);

            // ReSharper disable once InvertIf
            if (middlewareBundle != null)
            {
                foreach (var middleware in middlewareBundle)
                {
                    // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
                    if (middleware is IBindingMiddleware)
                    {
                        Use((IBindingMiddleware)middleware);
                    }
                    else if (middleware is IMessageMiddleware)
                    {
                        Use((IMessageMiddleware)middleware);
                    }
                    else if (middleware is ICleanupMiddleware)
                    {
                        Use((ICleanupMiddleware)middleware);
                    }
                    else if (middleware is IPublishMiddleware)
                    {
                        Use((IPublishMiddleware)middleware);
                    }
                    else
                    {
                        throw new ArgumentException($"Unsupported middleware implementation: {(middleware == null ? "null" : middleware.GetType().Name)}");
                    }
                }
            }

            return(this);
        }