private static JsonMediaTypeFormatter CreateJsonFormatter(TrendyolAppBuilder builder) { IDateTimeProvider dateTimeProvider = builder.DataStore.GetData <IDateTimeProvider>(App.Constants.DateTimeProvider); JsonSerializerSettings settings; if (dateTimeProvider != null && dateTimeProvider.Kind == DateTimeKind.Local) { settings = TrendyolApp.GetJsonSerializerSettings(DateTimeZoneHandling.Local); } else if (dateTimeProvider != null && dateTimeProvider.Kind == DateTimeKind.Utc) { settings = TrendyolApp.GetJsonSerializerSettings(DateTimeZoneHandling.Utc); } else { settings = TrendyolApp.GetJsonSerializerSettings(); } JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter() { SerializerSettings = settings }; return(formatter); }
public TrendyolWebApiBuilder(TrendyolAppBuilder builder, IAppBuilder owinBuilder, string applicationName) : base(builder) { _appBuilder = builder; _applicationName = applicationName; _owinBuilder = owinBuilder; }
public static TrendyolAppBuilder UseAutomaticMigrations <T>(this TrendyolAppBuilder builder) where T : DbMigrationsConfiguration { builder.AfterBuild(() => { T configuration = Activator.CreateInstance <T>(); DbMigrator migrator = new DbMigrator(configuration); migrator.Update(); }); return(builder); }
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 TrendyolAppBuilder UseMvc(this TrendyolAppBuilder builder, Action <RouteCollection> registerRoutesAction = null, Action <BundleCollection> registerBundles = null) { ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); RouteTable.Routes.LowercaseUrls = true; RouteTable.Routes.MapMvcAttributeRoutes(); registerRoutesAction?.Invoke(RouteTable.Routes); registerBundles?.Invoke(BundleTable.Bundles); return(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); }
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); }
public static TrendyolAppBuilder UseDaemon <T>(this TrendyolAppBuilder appBuilder, string serviceName, int defaultStartStopTimeoutInMinutes = 3, ServiceAccountType serviceAccountType = ServiceAccountType.LocalSystem, string serviceAccountUserName = "", string serviceAccountPassword = "", params string[] dependencies) where T : TrendyolWindowsService { appBuilder.AfterBuild(() => { HostFactory.Run(x => { x.Service <T>(s => { s.ConstructUsing(srv => Activator.CreateInstance <T>()); s.WhenStarted(srv => srv.Start()); s.WhenStopped(srv => srv.Stop()); }); x.OnException((ex) => { Logger.Error($"There was a problem executing {serviceName}.", ex); }); x.StartAutomatically(); x.SetStartTimeout(TimeSpan.FromMinutes(defaultStartStopTimeoutInMinutes)); x.SetStopTimeout(TimeSpan.FromMinutes(defaultStartStopTimeoutInMinutes)); x.SetDescription(serviceName); x.SetDisplayName(serviceName); x.SetServiceName(serviceName); if (dependencies != null && dependencies.Any()) { foreach (string dependency in dependencies) { x.AddDependency(dependency); } } switch (serviceAccountType) { case ServiceAccountType.LocalSystem: x.RunAsLocalSystem(); break; case ServiceAccountType.Custom: if (String.IsNullOrEmpty(serviceAccountUserName)) { throw new ArgumentException("ServiceAccountUserName cannot be null when account type is set to custom.", nameof(serviceAccountUserName)); } if (String.IsNullOrEmpty(serviceAccountPassword)) { throw new ArgumentException("ServiceAccountPassword cannot be null when account type is set to custom.", nameof(serviceAccountPassword)); } x.RunAs(serviceAccountUserName, serviceAccountPassword); break; default: throw new ArgumentOutOfRangeException(nameof(serviceAccountType), serviceAccountType, null); } }); }); return(appBuilder); }
public TrendyolDataContextBuilder(TrendyolAppBuilder builder) : base(builder) { _appBuilder = builder; }