Пример #1
0
        public static IServiceCollection AddJsonApi(this IServiceCollection services, IMvcBuilder mvcBuilder,
                                                    ContainerBuilder containerBuilder, IConfiguration configuration,
                                                    Action <IMapperConfigurationExpression> configure)
        {
            // setup auto mapper
            var    siteOptions = configuration.GetOptions <SiteOptions>();
            string siteKey     = siteOptions.Id;

            services.AddAutoMapper(mapConfig =>
            {
                mapConfig.ValidateInlineMaps = false;
                mapConfig.AddProfile(new XFMapperProfile(siteKey));
                configure(mapConfig);
            }, new Assembly[0]);

            JsonApiOptions.ResourceNameFormatter = new XFResourceNameFormatter();
            var graphBuilder = new XFResourceGraphBuilder();
            // find all resources
            var assemblies = new[] { Assembly.GetEntryAssembly(), Assembly.GetExecutingAssembly() };

            ResourceDescriptor[] resourceDescriptors = assemblies
                                                       .SelectMany(a => ResourceTypeLocator.GetIdentifableTypes(a)).ToArray();
            foreach (ResourceDescriptor resourceDescriptor in resourceDescriptors)
            {
                // add resource to graph
                string resourceName = JsonApiOptions.ResourceNameFormatter.FormatResourceName(
                    resourceDescriptor.ResourceType);
                graphBuilder.AddResource(resourceDescriptor.ResourceType, resourceDescriptor.IdType, resourceName);

                // register resource service
                Type   serviceInterfaceType = typeof(IResourceService <,>);
                Type[] genericArguments     = new[] { resourceDescriptor.ResourceType, resourceDescriptor.IdType };
                Type   serviceType          = ResourceTypeLocator.GetGenericInterfaceImplementation(
                    resourceDescriptor.ResourceType.Assembly, serviceInterfaceType, genericArguments);
                if (serviceType != null)
                {
                    RegisterResourceService(containerBuilder, serviceType);
                }
            }

            var jsonApiOptions = new JsonApiOptions
            {
                Namespace               = XForgeConstants.JsonApiNamespace,
                ResourceGraph           = graphBuilder.Build(),
                AllowClientGeneratedIds = true,
                IncludeTotalRecordCount = true
            };

            jsonApiOptions.SerializerSettings.ContractResolver = new JsonApiContractResolver();
            jsonApiOptions.SerializerSettings.Converters.Add(new StringEnumConverter());

            mvcBuilder.AddMvcOptions(options =>
            {
                options.Filters.Add(typeof(JsonApiExceptionFilter));
                options.Filters.Add(typeof(TypeMatchFilter));
                SerializeAsJsonApi(options, jsonApiOptions);
            });

            services.AddJsonApiInternals(jsonApiOptions);
            services.AddScoped <IDocumentBuilder, XFDocumentBuilder>();

            // generate resource schema
            var schema = ResourceSchema.Build(jsonApiOptions.ResourceGraph, resourceDescriptors);

            services.AddSingleton(schema);

            return(services);
        }
Пример #2
0
        public static IMvcBuilder AddExceptionHandlingConfiguration(this IMvcBuilder builder)
        {
            builder.AddMvcOptions(options => options.Filters.Add(new ApiExceptionFilterAttribute()));

            return(builder);
        }
 public static IMvcBuilder AddModelValidator(this IMvcBuilder builder)
 {
     return(builder.AddMvcOptions(options => options.Filters.Add(new ModelValidatorFilterAttribute())));
 }
        public static IMvcBuilder AddApiExtensions(this IMvcBuilder builder, IConfigurationSection config = null, Action <ApiExtensionOptions> build = null)
        {
            var apiOptions = new ApiExtensionOptions();

            #region Include services needed for building uri's in the paging object

            builder.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            builder.Services.TryAddSingleton <IActionContextAccessor, ActionContextAccessor>();

            builder.Services.AddScoped <IUrlHelper>(x =>
            {
                var actionContext = x.GetService <IActionContextAccessor>().ActionContext;
                return(new UrlHelper(actionContext));
            });

            builder.Services.TryAddSingleton <ILinkProvider, LinkProvider>();
            #endregion

            #region Register Options

            if (config != null && build != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(x => { });
            }
            if (config != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(config);

                config.Bind(apiOptions);
            }
            if (build != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(build);
                build(apiOptions);
            }

            #endregion

            #region Configuration from options

            if (!apiOptions.DisableGlobalErrorHandling && !apiOptions.DisableGlobalExceptionFilter)
            {
                builder.AddMvcOptions(options =>
                {
                    options.Filters.Add(typeof(GlobalExceptionFilter));
                });
            }

            if (!apiOptions.DisableVersioning)
            {
                builder.AddMvcOptions(options =>
                {
                    options.Conventions.Insert(0, new RouteConvention(new RouteAttribute("{apiVersion}")));
                });
            }

            #endregion

            builder.AddMvcOptions(options =>
            {
                options.Filters.Insert(0, new ConsumesAttribute("application/json"));
                options.Filters.Insert(1, new ProducesAttribute("application/json"));

                options.ModelBinderProviders.Insert(0, new CommaDelimitedArrayModelBinderProvider());

                JsonOutputFormatter jsonFormatter = options.OutputFormatters.OfType <JsonOutputFormatter>().FirstOrDefault();

                jsonFormatter?.SupportedMediaTypes.Add("application/hal+json");
            });

            builder.AddJsonOptions(x =>
            {
                x.SerializerSettings.ContractResolver     = new BaseContractResolver();
                x.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                x.SerializerSettings.NullValueHandling    = NullValueHandling.Ignore;
                x.SerializerSettings.Converters.Add(new TimeSpanConverter());
                x.SerializerSettings.Converters.Add(new PagedResultConverter());
                x.SerializerSettings.Converters.Add(new GuidConverter());
                x.SerializerSettings.Formatting = Formatting.None;
            });

            return(builder);
        }
Пример #5
0
 protected override void BuildMvc(IMvcBuilder mvcBuilder)
 {
     mvcBuilder.AddMvcOptions(option => option.EnableEndpointRouting = false);
     base.BuildMvc(mvcBuilder);
 }
Пример #6
0
 /// <summary>
 ///   Add HateoasFormatter to MvcBuilder OutputFormatters
 /// </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static IMvcBuilder AddHateoasFormatter(this IMvcBuilder builder)
 {
     return(builder.AddMvcOptions(o => o.OutputFormatters.Add(new HateoasFormatter())));
 }
 public static IMvcBuilder AddAssignmentsCSVFormatter(this IMvcBuilder builder) =>
 builder.AddMvcOptions(config => config.OutputFormatters.Add(new
                                                             AssignmentsCsvOutputFormatter()));
Пример #8
0
 public static IMvcBuilder AddSpecHandling(this IMvcBuilder mvcBuilder) =>
 mvcBuilder.AddMvcOptions(o => o.Filters.Add <SpecExceptionFilter>());
 /// <summary>
 /// Configures Mvc to use global filters.
 /// </summary>
 public static IMvcBuilder AddAndConfigureFilters(this IMvcBuilder mvcBuilder, ILoggerFactory loggerFactory)
 {
     return(mvcBuilder.AddMvcOptions(options => {
         options.Filters.Add(new ValidatorActionFilter(loggerFactory.CreateLogger <ValidatorActionFilter>()));
     }));
 }
 /// <summary>
 /// Adds an action filter required to safely throw <see cref="HttpException" /> in action methods.
 /// </summary>
 /// <param name="builder">The ASP.NET MVC builder.</param>
 public static IMvcBuilder AddHttpErrors(this IMvcBuilder builder)
 => builder.AddMvcOptions(o => o.Filters.Add(new HttpExceptionActionFilter()));
Пример #11
0
 public static IMvcBuilder AddFilters(this IMvcBuilder mvcBuilder)
 {
     return(mvcBuilder.AddMvcOptions(opt => {
         opt.Filters.Add(new FillLangIdParametrFilter());
     }));
 }
        public static IMvcBuilder AddApiExtensions(this IMvcBuilder builder, IConfigurationSection config = null, Action <ApiExtensionOptions> build = null, Type exception = null)
        {
            var apiOptions = new ApiExtensionOptions();

            #region Include services needed for building uri's in the paging object

            builder.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            builder.Services.TryAddSingleton <IActionContextAccessor, ActionContextAccessor>();

            #endregion

            #region Register Options

            if (config != null && build != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(x => { });
            }
            if (config != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(config);
                config.Bind(apiOptions);
            }
            if (build != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(build);
                build(apiOptions);
            }

            #endregion

            #region Configuration from options

            if (!apiOptions.DisableGlobalErrorHandling)
            {
                builder.AddMvcOptions(options =>
                {
                    options.Filters.Add(typeof(GlobalExceptionFilter));
                });
            }

            if (!apiOptions.DisableVersioning)
            {
                builder.AddMvcOptions(options =>
                {
                    options.Conventions.Insert(0, new RouteConvention(new RouteAttribute("{apiVersion}")));
                });
            }

            #endregion

            builder.AddMvcOptions(options =>
            {
                options.Filters.Add(new PagedResultAttribute()
                {
                    Order = 1000
                });
            });

            builder.AddJsonOptions(x =>
            {
                x.SerializerSettings.ContractResolver     = new BaseContractResolver();
                x.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                x.SerializerSettings.NullValueHandling    = NullValueHandling.Ignore;
                x.SerializerSettings.Converters.Add(new TimeSpanConverter());
                x.SerializerSettings.Converters.Add(new GuidConverter());
                x.SerializerSettings.Formatting = Formatting.None;
            });

            return(builder);
        }
Пример #13
0
 public static IMvcBuilder AddCsvFormatter(this IMvcBuilder mvcBuilder) =>
 mvcBuilder.AddMvcOptions(options =>
 {
     options.InputFormatters.Add(new CsvInputFormatter());
     options.OutputFormatters.Add(new CsvOutputFormatter());
 });
Пример #14
0
 /// <summary>
 /// Adds services necessary to bind <see cref="ODataOptions{TEntity}" /> as an action method parameter.
 /// </summary>
 /// <param name="builder">The ASP.NET MVC builder.</param>
 /// <param name="primitiveTypes">An enumeration of additional primitive types.</param>
 /// <param name="isCaseSensitive">Indicates whether the property binding is case sensitive.</param>
 public static IMvcBuilder AddOData(this IMvcBuilder builder, IEnumerable <IPrimitiveType> primitiveTypes, bool isCaseSensitive)
 {
     return(builder.AddMvcOptions(o => o.ModelBinderProviders.Insert(0, new ODataOptionsModelBinderProvider(primitiveTypes, isCaseSensitive))));
 }
Пример #15
0
        public void RegisterServices(IMvcBuilder mvcBuilder, IServiceCollection services, IConfigurationRoot configuration)
        {
            //Inject AOP logger
            services.AddScoped(lg => LogManager.GetLogger(typeof(LoggingMiddleware)));

            //Injecting DB Connection,Dapper,UnitOfWork
            //Injecting DB Connection,Dapper,UnitOfWork
            services.AddScoped <IDbConnection>(c => new System.Data.SqlClient.SqlConnection(configuration.GetSection("configuration:connectionStrings:1:connectionString").Value));
            services.AddScoped <IDapperWrapper, DapperWrapper>();
            services.AddScoped <IDbProvider, DbProvider>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();

            //Injecting Business rules
            services.AddScoped(typeof(IRulesEngine <>), typeof(BaseRulesEngine <>));

            //Helper
            services.AddScoped <IDbHelper, DbHelper>();

            //Injecting all repositories
            services.AddScoped <ICustomerRepository <Customer>, CustomerRepository>();

            //Sevices
            services.AddScoped <ICustomerService, CustomerService>();



            //Helper

            //inject json settings
            services.Configure <ConfigurationSettings>(configuration.GetSection("ApplicationSettings"));

            mvcBuilder.AddJsonOptions(options =>
            {
                options.SerializerSettings.Converters.Add(new StringEnumConverter()); //Json serializer settings Enum as string
            });

            //Adding domain Events



            //Injecting API Versioning
            services.AddApiVersioning(c => {
                c.AssumeDefaultVersionWhenUnspecified = true;
                c.ApiVersionReader = new QueryStringOrHeaderApiVersionReader()
                {
                    HeaderNames = { "api-version" }
                };
            });

            //Injecting Filters
            services.AddScoped <ValidateActionFilterAttribute>();
            services.AddScoped <ExceptionActionFilterAttribute>();
            services.AddScoped <IExceptionService, ExceptionService>();

            mvcBuilder.AddMvcOptions(options =>
            {
                options.ModelValidatorProviders.Clear(); //Clearing existing validators since we are managing our own model validation.
            });

            services.Add(ServiceDescriptor.Scoped(typeof(IValidatorFactory), typeof(ServiceProviderValidatorFactory)));
            RegisterValidatorsFromAssemblyContainingType <BaseDto>(services);
            services.AddScoped <IValidationService, ValidationService>();

            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            //Automapper to DI
            services.AddAutoMapper();
        }
 public static IMvcBuilder AddGenericControllers(this IMvcBuilder mvcBuilder, Action <IGenericControllersOptions> genericControllersOptionsAction) =>
 mvcBuilder
 .AddMvcOptions(moa => moa.Conventions.Add(new GenericControllerNameConvention()))
 .ConfigureApplicationPartManager(apm => apm.FeatureProviders
                                  .Add(new GenericControllerFeatureProvider(genericControllersOptionsAction)));
Пример #17
0
 public static IMvcBuilder AddApiPagination(this IMvcBuilder builder)
 {
     return(builder.AddMvcOptions(ConfigureMvcOptions));
 }
Пример #18
0
 public static void AddCustomHkpFormatter(this IMvcBuilder builder) =>
 builder.AddMvcOptions(config => config.OutputFormatters.Add(new HkpOutputFormatter()));
Пример #19
0
        public static IMvcBuilder AddApiExtensions(this IMvcBuilder builder, IConfigurationSection config = null, Action <ApiExtensionOptions> build = null)
        {
            var apiOptions = new ApiExtensionOptions();

            #region Include services needed for building uri's in the paging object

            builder.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            builder.Services.TryAddSingleton <IActionContextAccessor, ActionContextAccessor>();

            builder.Services.AddScoped <IUrlHelper>(x =>
            {
                var actionContext = x.GetService <IActionContextAccessor>().ActionContext;
                return(new UrlHelper(actionContext));
            });

            builder.Services.AddScoped <ILinkProvider, LinkProvider>();
            #endregion

            #region Register Options

            if (config != null && build != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(x => { });
            }
            if (config != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(config);

                config.Bind(apiOptions);
            }
            if (build != null)
            {
                builder.Services.Configure <ApiExtensionOptions>(build);
                build(apiOptions);
            }

            #endregion

            #region Configuration from options

            if (!apiOptions.DisableVersioning)
            {
                builder.AddMvcOptions(options =>
                {
                    options.Conventions.Insert(0, new RouteConvention(new RouteAttribute("{apiVersion}")));
                });

                builder.Services.ConfigureSwaggerGen(options =>
                {
                    options.DocInclusionPredicate((version, apiDescription) =>
                    {
                        if (!apiDescription.TryGetMethodInfo(out MethodInfo methodInfo))
                        {
                            return(false);
                        }

                        var allowedVersions = methodInfo.GetCustomAttributes(true).OfType <VersionsAttribute>().FirstOrDefault();
                        return(allowedVersions != null && allowedVersions.AcceptedVersions.Contains(version));
                    });
                });
            }


            #endregion

            builder.AddMvcOptions(options =>
            {
                options.Filters.Insert(0, new ConsumesAttribute("application/json"));
                options.Filters.Insert(1, new ProducesAttribute("application/json"));

                options.ModelBinderProviders.Insert(0, new CommaDelimitedArrayModelBinderProvider());

                JsonOutputFormatter jsonFormatter = options.OutputFormatters.OfType <JsonOutputFormatter>().FirstOrDefault();

                jsonFormatter?.SupportedMediaTypes.Add("application/hal+json");
            });

            builder.AddJsonOptions(x =>
            {
                x.SerializerSettings.Initialize();
            });

            return(builder);
        }
Пример #20
0
 public static void AddMessagePack(this IMvcBuilder builder)
 {
     builder.Services.Add(new ServiceDescriptor(typeof(MessagePackOptions), new MessagePackOptions()));
     builder.AddMvcOptions((options) => options.InputFormatters.Add(new MessagePackInputMediaTypeFormatter()));
     builder.AddMvcOptions((options) => options.OutputFormatters.Add(new MessagePackOutputMediaTypeFormatter()));
 }
Пример #21
0
 public static IMvcBuilder AddAuthorizationPolicy(this IMvcBuilder builder)
 {
     return(builder.AddMvcOptions(options => options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()))));
 }
Пример #22
0
 /// <summary>
 ///     Add the class <typeparamref name="T" /> to the <see cref="FilterCollection" /> for <paramref name="mvc" />.
 /// </summary>
 /// <typeparam name="T">Type to wrap a <see cref="MiddlewareFilterAttribute" /> around.</typeparam>
 /// <param name="mvc"></param>
 /// <returns>Instance of <see cref="IMvcBuilder"/>.</returns>
 public static IMvcBuilder AddRequestLocalizationFilter <T>(this IMvcBuilder mvc)
 {
     mvc.AddMvcOptions(options =>
                       options.Filters.Add(new MiddlewareFilterAttribute(typeof(T))));
     return(mvc);
 }
Пример #23
0
 /// <summary>
 ///     Configue the <see cref="IMvcBuilder" /> to insert the <see cref="FlagsEnumModelBinder" />.
 /// </summary>
 /// <param name="builder">The <see cref="IMvcBuilder" /> object to be configuring.</param>
 /// <returns>The <paramref name="builder" /> object.</returns>
 public static IMvcBuilder AddFlagsEnumModelBinderProvider(this IMvcBuilder builder)
 {
     builder.AddMvcOptions(options => AddFlagsEnumModelBinderProvider(options));
     return(builder);
 }
 public static void AddCybtansFormatter(this IMvcBuilder builder, Encoding?encoding = null)
 {
     builder.AddMvcOptions(options => options.AddCytansFormatter(encoding));
 }
Пример #25
0
 public static IMvcBuilder AddFeatures(this IMvcBuilder builder, IConfiguration configuration)
 {
     builder.Services.AddTransient <IFeatureService>(provider => new FeatureService(configuration));
     builder.AddMvcOptions(options => options.Filters.Add(typeof(FeatureFilter)));
     return(builder);
 }
Пример #26
0
        /// <summary>
        /// ConfigureServices is where you register dependencies. This gets called by the runtime
        /// before the Configure method, below.
        /// </summary>
        /// <param name="services">Specifies the contract for a collection of service descriptors.</param>
        /// <returns>Un IServiceProvider.</returns>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add services to the collection.
            IMvcBuilder mvcBuilder = services.AddMvc();

            // Configura el manejador global de excepciones.
            services.AddSingleton <GlobalExceptionFilter>();

            // Setup global exception filters.
            mvcBuilder.AddMvcOptions(
                options =>
            {
                FilterCollection filters = options.Filters;
                ServiceFilterAttribute exceptionFilter =
                    new ServiceFilterAttribute(typeof(GlobalExceptionFilter));
                filters.Add(exceptionFilter);

                // ServiceFilterAttribute validationFilter = new ServiceFilterAttribute(typeof(ValidateModelFilter));
                filters.Add(typeof(ValidateModelFilter));
            });

            // Doc: https://github.com/domaindrivendev/Swashbuckle.AspNetCore
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Training.Persona.Api", Version = "v1"
                });
                c.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "Training.Persona.Api.xml"));
                c.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "Training.Persona.Entities.xml"));
                c.DescribeAllEnumsAsStrings();
                c.IgnoreObsoleteActions();
                c.OperationFilter <SwaggerGenResponseFilter>();
            });

            // Create the container builder.
            ContainerBuilder builder = new ContainerBuilder();

            // Register dependencies, populate the services from the collection, and build the container.
            builder.Populate(services);

            // Registra la configuración (appsettings.json).
            builder.RegisterInstance(this.Configuration).AsImplementedInterfaces().SingleInstance();

            builder.RegisterModule <Persona.Ioc.PersonaModule>();

            // Registra y mapea los Settings (ConnectionStrings).
            builder.Register(
                c =>
            {
                // Resuelve el ConfigurationRoot.
                IConfigurationRoot configurationRoot = c.Resolve <IConfigurationRoot>();

                // Obtiene la sección del .json de settings.
                IConfigurationSection section = configurationRoot.GetSection("ConnectionStrings");

                // Mapea la sección del .json a la clase.
                Apollo.NetCore.Core.Settings.ConnectionStrings connStr = new Apollo.NetCore.Core.Settings.ConnectionStrings();
                ConfigurationBinder.Bind(section, connStr);

                return(connStr);
            }).As <Apollo.NetCore.Core.Settings.ConnectionStrings>()

            .SingleInstance();

            this.ApplicationContainer = builder.Build();

            // Create the IServiceProvider based on the container.
            return(new AutofacServiceProvider(this.ApplicationContainer));
        }
Пример #27
0
 public static IMvcBuilder ConfigureMVCForDS(this IMvcBuilder mvcBuilder) =>
 mvcBuilder.AddMvcOptions(options => options.Filters.Add <LocalsFilter>());
 public static IMvcBuilder AddValigatorJsonExceptionFilter(this IMvcBuilder builder, Func <ValigatorSerializationException, IActionResult> errorCreater)
 => builder
 .AddMvcOptions(options => options.AddValigatorJsonExceptionHandler(errorCreater));
Пример #29
0
 public static IMvcBuilder AddCustomCSVFormatter(this IMvcBuilder builder) =>
 builder.AddMvcOptions(config => config.OutputFormatters.Add(new CsvOutputFormatter()));
Пример #30
0
        /// <summary>
        /// 注册Workflow Rest服务
        /// </summary>
        /// <param name="mvcBuilder"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static IMvcBuilder AddProcessEngineRestServices(this IMvcBuilder mvcBuilder, IConfiguration config)
        {
            IServiceCollection services = mvcBuilder.Services;

            mvcBuilder.AddMvcOptions(opts =>
            {
                JsonOutputFormatter jsonFormatter = opts.OutputFormatters.FirstOrDefault(x => x.GetType() == typeof(JsonOutputFormatter)) as JsonOutputFormatter;

                if (jsonFormatter != null)
                {
                    //jsonFormatter.PublicSerializerSettings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple;
                    //jsonFormatter.PublicSerializerSettings.TypeNameHandling = TypeNameHandling.All;
                    jsonFormatter.PublicSerializerSettings.ReferenceLoopHandling =
                        ReferenceLoopHandling.Ignore;
                }

                opts.ModelBinderProviders.Insert(0, new PageableModelBinderProvider());
            });

            services.AddTransient <ProcessInstanceSortApplier>();

            services.AddSingleton <PageRetriever>();

            services.AddTransient <HistoricInstanceConverter>();

            services.AddTransient <HistoryInstanceSortApplier>();

            services.AddTransient <PageableProcessHistoryRepositoryService>(sp =>
            {
                return(new PageableProcessHistoryRepositoryService(
                           sp.GetService <PageRetriever>(),
                           sp.GetService <IProcessEngine>().HistoryService,
                           sp.GetService <HistoryInstanceSortApplier>(),
                           sp.GetService <HistoricInstanceConverter>(),
                           sp.GetService <SecurityPoliciesApplicationService>(),
                           sp.GetService <ILoggerFactory>()
                           ));
            });

            services.AddTransient <PageableProcessInstanceRepositoryService>(sp =>
            {
                IProcessEngine engine = sp.GetService <IProcessEngine>();

                return(new PageableProcessInstanceRepositoryService(sp.GetService <PageRetriever>(),
                                                                    engine.RuntimeService,
                                                                    sp.GetService <ProcessInstanceSortApplier>(),
                                                                    sp.GetService <ProcessInstanceConverter>(),
                                                                    sp.GetService <ILoggerFactory>()));
            });

            services.AddTransient <ListConverter>();

            services.AddTransient <TaskConverter>(sp => new TaskConverter(sp.GetService <ListConverter>()));

            services.AddTransient <HistoricTaskInstanceConverter>(sp => new HistoricTaskInstanceConverter(sp.GetService <ListConverter>()));

            services.AddTransient <TaskSortApplier>();

            services.AddTransient <HistoryTaskSortApplier>();

            //services.AddTransient<MessageProducerActivitiEventListener>();

            services.AddTransient <PageableTaskRepositoryService>(sp =>
            {
                IProcessEngine engine = sp.GetService <IProcessEngine>();

                return(new PageableTaskRepositoryService(
                           engine.TaskService,
                           sp.GetService <TaskConverter>(),
                           sp.GetService <HistoricTaskInstanceConverter>(),
                           sp.GetService <IHistoryService>(),
                           sp.GetService <PageRetriever>(),
                           sp.GetService <TaskSortApplier>(),
                           sp.GetService <HistoryTaskSortApplier>()));
            });

            services.AddTransient <ProcessInstanceConverter>(sp =>
            {
                IProcessEngine engine = sp.GetService <IProcessEngine>();

                return(new ProcessInstanceConverter(sp.GetService <ListConverter>()));
            });

            services.AddTransient <ProcessInstanceResourceAssembler>();

            services.AddScoped <ProcessEngineWrapper>(sp =>
            {
                IProcessEngine engine = sp.GetService <IProcessEngine>();

                IHttpContextAccessor httpContext = sp.GetService <IHttpContextAccessor>();

                return(new ProcessEngineWrapper(sp.GetService <ProcessInstanceConverter>(),
                                                sp.GetService <PageableProcessInstanceRepositoryService>(),
                                                sp.GetService <TaskConverter>(),
                                                sp.GetService <PageableTaskRepositoryService>(),
                                                null,
                                                sp.GetService <SecurityPoliciesApplicationService>(),
                                                null,
                                                null,
                                                engine,
                                                sp.GetService <HistoricInstanceConverter>(),
                                                sp.GetService <ILoggerFactory>()));
            });

            services.AddScoped <SecurityPoliciesApplicationService>();

            services
            .AddTransient <PageRetriever>()
            .AddTransient <ProcessDefinitionConverter>()
            .AddTransient <ProcessDefinitionSortApplier>()
            .AddTransient <ProcessDefinitionResourceAssembler>()
            .AddTransient <ProcessDefinitionMetaResourceAssembler>()
            .AddTransient <DeploymentConverter>()
            .AddTransient <DeploymentSortApplier>()
            .AddTransient <PageableProcessDefinitionRepositoryService>()
            .AddTransient <PageableDeploymentRespositoryService>();

            services.AddTransient <TaskVariableResourceAssembler>();

            services.AddTransient <TaskResourceAssembler>();

            services.AddTransient <ProcessInstanceVariableResourceAssembler>();

            services.AddTransient <AuthenticationWrapper>();

            services.AddTransient <IMvcControllerDiscovery, MvcControllerDiscovery>();

            mvcBuilder.AddApplicationPart(typeof(ProcessEngineRestExtention).Assembly);

            return(mvcBuilder);
        }