Exemple #1
0
        public TrendyolWebApiBuilder WithHttpsGuard()
        {
            _appBuilder.BeforeBuild(() =>
            {
                HttpConfiguration config = _appBuilder.DataStore.GetData <HttpConfiguration>(Constants.HttpConfigurationDataKey);

                if (config == null)
                {
                    throw new ConfigurationErrorsException(
                        "You must register your app with UseWebApi method before calling UseHttpsGuard.");
                }

                config.MessageHandlers.Add(new HttpsGuard());
            });

            return(this);
        }
Exemple #2
0
        public static TrendyolDataContextBuilder <T> UseDataContext <T>(this TrendyolAppBuilder builder) where T : DataContextBase
        {
            builder.BeforeBuild(() =>
            {
                Database.SetInitializer <T>(null);
                var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
                DbInterception.Add(new WithNoLockInterceptor());
            });

            return(new TrendyolDataContextBuilder <T>(builder));
        }
        public static TrendyolWebApiBuilder UseWebApi(this TrendyolAppBuilder builder, IAppBuilder app, string applicationName, string customSwaggerContentPath = null)
        {
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            builder.BeforeBuild(() =>
            {
                HttpConfiguration config = new HttpConfiguration();

                string rootUrl = builder.DataStore.GetData <string>(Constants.ApiRootUrlDataKey);

                config.EnableSwagger("docs/{apiVersion}/swagger", c =>
                {
                    c.SingleApiVersion("v1", applicationName)
                    .Description($"{applicationName} documentation.");
                    c.DescribeAllEnumsAsStrings(true);

                    if (!String.IsNullOrEmpty(rootUrl))
                    {
                        c.RootUrl(r => rootUrl);
                    }
                })
                .EnableSwaggerUi("help/{*assetPath}", c =>
                {
                    if (!String.IsNullOrEmpty(customSwaggerContentPath))
                    {
                        c.InjectJavaScript(callingAssembly, $"{callingAssembly.GetName().Name}.{customSwaggerContentPath}");
                    }

                    c.DisableValidator();
                });

                config.MapHttpAttributeRoutes();
                config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });

                config.Formatters.Clear();
                config.Formatters.Add(CreateJsonFormatter());
                config.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));
                config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());

                builder.DataStore.SetData(Constants.HttpConfigurationDataKey, config);
            });

            builder.AfterBuild(() =>
            {
                HttpConfiguration config = builder.DataStore.GetData <HttpConfiguration>(Constants.HttpConfigurationDataKey);
                app.UseWebApi(config);
            });

            return(new TrendyolWebApiBuilder(builder, app, applicationName));
        }
        public static TrendyolAppBuilder UseNLog(this TrendyolAppBuilder builder)
        {
            builder.BeforeBuild(() =>
            {
                NameValueCollection properties = new NameValueCollection
                {
                    ["configType"] = "FILE",
                    ["configFile"] = "~/NLog.config"
                };

                LogManager.Adapter = new NLogLoggerFactoryAdapter(properties);
            });

            return(builder);
        }
Exemple #5
0
        public static TrendyolAppBuilder UseAutofacWebApi(this TrendyolAppBuilder builder, Assembly controllerAssembly)
        {
            builder.BeforeBuild(() =>
            {
                ContainerBuilder containerBuilder = builder.DataStore.GetData <ContainerBuilder>(Autofac.Constants.AutofacContainerBuilderDataKey);
                containerBuilder.RegisterApiControllers(controllerAssembly);
            });

            builder.AfterBuild(() =>
            {
                HttpConfiguration config  = builder.DataStore.GetData <HttpConfiguration>(WebApi.Constants.HttpConfigurationDataKey);
                IContainer container      = builder.DataStore.GetData <IContainer>(Autofac.Constants.AutofacContainerDataKey);
                config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            });

            return(builder);
        }
        public static TrendyolAppBuilder UseAutofac(this TrendyolAppBuilder builder, Action <ContainerBuilder> action = null, Assembly serviceAssembly = null, Assembly dataAssembly = null)
        {
            builder.BeforeBuild(() =>
            {
                ContainerBuilder containerBuilder = new ContainerBuilder();

                if (serviceAssembly != null)
                {
                    containerBuilder
                    .RegisterAssemblyTypes(serviceAssembly)
                    .Where(item => item.Implements(typeof(IService)) && item.IsAbstract == false)
                    .AsImplementedInterfaces()
                    .SingleInstance();
                }

                if (dataAssembly != null)
                {
                    containerBuilder
                    .RegisterAssemblyTypes(dataAssembly)
                    .Where(item => item.Implements(typeof(IRepository)) && item.IsAbstract == false)
                    .AsImplementedInterfaces()
                    .SingleInstance();

                    containerBuilder
                    .RegisterAssemblyTypes(dataAssembly)
                    .Where(item => item.Implements(typeof(IIdentityProvider)) && item.IsAbstract == false)
                    .AsImplementedInterfaces()
                    .SingleInstance();
                }

                action?.Invoke(containerBuilder);

                builder.DataStore.SetData(Constants.AutofacContainerBuilderDataKey, containerBuilder);
            });

            builder.AfterBuild(() =>
            {
                ContainerBuilder containerBuilder = builder.DataStore.GetData <ContainerBuilder>(Constants.AutofacContainerBuilderDataKey);
                IContainer container = containerBuilder.Build();
                builder.DataStore.SetData(Constants.AutofacContainerDataKey, container);
            });

            return(builder);
        }
        public static TrendyolAppBuilder UseAutofacMvc(this TrendyolAppBuilder builder, Assembly controllerAssembly)
        {
            builder.BeforeBuild(() =>
            {
                ContainerBuilder containerBuilder = builder.DataStore.GetData <ContainerBuilder>(Autofac.Constants.AutofacContainerBuilderDataKey);

                containerBuilder
                .RegisterAssemblyTypes(controllerAssembly)
                .Where(item => item.Implements(typeof(IControllerHandler)) && item.IsAbstract == false)
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();

                containerBuilder.RegisterControllers(controllerAssembly);
            });

            builder.AfterBuild(() =>
            {
                IContainer container = builder.DataStore.GetData <IContainer>(Autofac.Constants.AutofacContainerDataKey);
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            });

            return(builder);
        }