Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Startup"/> class.
        /// </summary>
        /// <param name="config">The <see cref="IConfiguration"/>.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        public Startup(IConfiguration config, ILoggerFactory loggerFactory)
        {
            // Use JSON property names in validation; default the page size and determine whether unhandled exception details are to be included in the response.
            ValidationArgs.DefaultUseJsonNames = true;
            PagingArgs.DefaultTake             = config.GetValue <int>("BeefDefaultPageSize");
            WebApiExceptionHandlerMiddleware.IncludeUnhandledExceptionInResponse = config.GetValue <bool>("BeefIncludeExceptionInInternalServerError");

            // Configure the logger.
            _logger = loggerFactory.CreateLogger("Logging");
            Logger.RegisterGlobal((largs) => WebApiStartup.BindLogger(_logger, largs));

            // Configure the cache policies.
            CachePolicyManager.SetFromCachePolicyConfig(config.GetSection("BeefCaching").Get <CachePolicyConfig>());
            CachePolicyManager.StartFlushTimer(CachePolicyManager.TenMinutes, CachePolicyManager.FiveMinutes);

#if (implement_database || implement_entityframework)
            // Register the database.
            AppNameDb.Register(() => new AppNameDb(WebApiStartup.GetConnectionString(config, "Database")));
#endif
#if (implement_cosmos)
            // Register the DocumentDb/CosmosDb client.
            AppNameCosmosDb.Register(() =>
            {
                var cs = config.GetSection("CosmosDb");
                return(new AppNameCosmosDb(new CosmosClient(cs.GetValue <string>("EndPoint"), cs.GetValue <string>("AuthKey")), cs.GetValue <string>("Database")));
            });
#endif
            // Register the ReferenceData provider.
            Beef.RefData.ReferenceDataManager.Register(new ReferenceDataProvider());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Startup"/> class.
        /// </summary>
        /// <param name="config">The <see cref="IConfiguration"/>.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        public Startup(IConfiguration config, ILoggerFactory loggerFactory)
        {
            // Use JSON property names in validation; and determine whether unhandled exception details are to be included in the response.
            ValidationArgs.DefaultUseJsonNames = true;
            WebApiExceptionHandlerMiddleware.IncludeUnhandledExceptionInResponse = config.GetValue <bool>("BeefIncludeExceptionInInternalServerError");

            // Add "page" and "page-size" to the supported paging query string parameters as defined by the CDR specification; and default the page size to 25 from config.
            WebApiQueryString.PagingArgsPageQueryStringNames.Add("page");
            WebApiQueryString.PagingArgsTakeQueryStringNames.Add("page-size");
            PagingArgs.DefaultTake = config.GetValue <int>("BeefDefaultPageSize");

            // Configure the logger.
            _logger = loggerFactory.CreateLogger("Logging");
            Logger.RegisterGlobal((largs) => WebApiStartup.BindLogger(_logger, largs));

            // Configure the cache policies.
            CachePolicyManager.SetFromCachePolicyConfig(config.GetSection("BeefCaching").Get <CachePolicyConfig>());
            CachePolicyManager.StartFlushTimer(CachePolicyManager.TenMinutes, CachePolicyManager.FiveMinutes);

            // Register the DocumentDb/CosmosDb client.
            CosmosDb.Register(() =>
            {
                var cs = config.GetSection("CosmosDb");
                return(new CosmosDb(new Microsoft.Azure.Cosmos.CosmosClient(cs.GetValue <string>("EndPoint"), cs.GetValue <string>("AuthKey")), cs.GetValue <string>("Database")));
            });

            // Register the ReferenceData provider.
            Beef.RefData.ReferenceDataManager.Register(new ReferenceDataProvider());

            // Register the "customised" execution context.
            Beef.ExecutionContext.Register(() => new ExecutionContext());
        }
Exemplo n.º 3
0
        protected override void OnStart(string[] args)
        {
            // TODO:  在此处添加代码以启动服务。
            _server = WebApiStartup.RunWebServer();
            Task.Factory.StartNew(() =>
            {
                syncServiceThread = Thread.CurrentThread;

                SyncServiceClientStartup.AutoSync();
            });
            Task.Factory.StartNew(() =>
            {
                marketingThread = Thread.CurrentThread;
                MarketingManager.InitStoreMarketing();
            });
            Task.Factory.StartNew(() =>
            {
                clientThread = Thread.CurrentThread;

                client = new PosStoreClient();
            });
            //Task.Factory.StartNew(() =>
            //{
            //    storeManagerThread = Thread.CurrentThread;
            //    IISExpressSeverManager manager = new IISExpressSeverManager();
            //    var config = StoreManageCenterConfig.GetConfig();
            //    var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Store");
            //    manager.Run(config.Port, path, "v4.0", "IIS");
            //});
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Startup"/> class.
        /// </summary>
        /// <param name="config">The <see cref="IConfiguration"/>.</param>
        public Startup(IConfiguration config)
        {
            // Use JSON property names in validation.
            ValidationArgs.DefaultUseJsonNames = true;

            // Load the cache policies.
            CachePolicyManager.SetFromCachePolicyConfig(config.GetSection("BeefCaching").Get <CachePolicyConfig>());
            CachePolicyManager.StartFlushTimer(CachePolicyManager.TenMinutes, CachePolicyManager.FiveMinutes);

            // Register the ReferenceData provider.
            Beef.RefData.ReferenceDataManager.Register(new ReferenceDataProvider());

#if (implement_database || implement_entityframework)
            // Register the database.
            Database.Register(() => new Database(WebApiStartup.GetConnectionString(config, "Database")));
#endif
#if (implement_cosmos)
            // Register the DocumentDb/CosmosDb client.
            CosmosDb.Register(() =>
            {
                var cs = config.GetSection("CosmosDb");
                return(new CosmosDb(new Cosmos.CosmosClient(cs.GetValue <string>("EndPoint"), cs.GetValue <string>("AuthKey")), cs.GetValue <string>("Database")));
            });
#endif
            // Default the page size.
            PagingArgs.DefaultTake = config.GetValue <int>("BeefDefaultPageSize");
        }
Exemplo n.º 5
0
        public Startup(IConfiguration config)
        {
            // Use JSON property names in validation.
            ValidationArgs.DefaultUseJsonNames = true;

            // Load the cache policies.
            CachePolicyManager.SetFromCachePolicyConfig(config.GetSection("BeefCaching").Get <CachePolicyConfig>());
            CachePolicyManager.StartFlushTimer(CachePolicyManager.TenMinutes, CachePolicyManager.FiveMinutes);

            // Register the ReferenceData provider.
            RefData.ReferenceDataManager.Register(new ReferenceDataProvider());

            // Register the database.
            Database.Register(() => new Database(WebApiStartup.GetConnectionString(config, "BeefDemo")));

            // Register the DocumentDb/CosmosDb client.
            CosmosDb.Register(() =>
            {
                var cs = config.GetSection("CosmosDb");
                return(new CosmosDb(new Cosmos.CosmosClient(cs.GetValue <string>("EndPoint"), cs.GetValue <string>("AuthKey")), cs.GetValue <string>("Database")));
            });

            // Register the test OData service.
            TestOData.Register(() => new TestOData(WebApiStartup.GetConnectionString(config, "TestOData")));

            // Default the page size.
            PagingArgs.DefaultTake = config.GetValue <int>("BeefDefaultPageSize");

            // Configure the Service Agents from the configuration and register.
            var sac = config.GetSection("BeefServiceAgents").Get <WebApiServiceAgentConfig>();

            sac?.RegisterAll();
        }
Exemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration config, ILoggerFactory loggerFactory, IHttpClientFactory clientFactory)
        {
            // Configure the logger.
            _logger = loggerFactory.CreateLogger("Logging");
            Logger.RegisterGlobal((largs) => WebApiStartup.BindLogger(_logger, largs));

            // Register the HttpClientCreate so it uses the factory.
            WebApiServiceAgentManager.RegisterHttpClientCreate((rd) =>
            {
                var hc         = clientFactory.CreateClient(rd.BaseAddress.AbsoluteUri);
                hc.BaseAddress = rd.BaseAddress;
                return(hc);
            });

            // Override the exception handling.
            WebApiExceptionHandlerMiddleware.IncludeUnhandledExceptionInResponse = config.GetValue <bool>("BeefIncludeExceptionInInternalServerError");
            app.UseWebApiExceptionHandler();

            // Set up the health checks.
            app.UseHealthChecks("/health");

            // Enable middleware to serve generated Swagger as a JSON endpoint and serve the swagger-ui.
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BEEF Demo"));

            // Configure the ExecutionContext for the request.
            app.UseExecutionContext((context, ec) =>
            {
                ec.Username  = context.User.Identity.Name ?? WebApiExecutionContextMiddleware.DefaultUsername;
                ec.Timestamp = DateTime.Now;
            });

            // Use mvc.
            app.UseMvc();
        }
Exemplo n.º 7
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     WebApiStartup.ApiConfigureServices(services, Configuration);
     services.AddDbContext <TEFContext>(options =>
                                        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                                        );
     services.AddScoped(typeof(DataContext), typeof(TEFContext));
 }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (AppSetting.GetObject <bool>("CreateDb"))
            {
                var context = app.ApplicationServices
                              .GetService <IServiceScopeFactory>()
                              .CreateScope()
                              .ServiceProvider
                              .GetRequiredService <TEFContext>();

                context.Database.EnsureCreated();
            }

            WebApiStartup.Configure(app, env);
        }
Exemplo n.º 9
0
        public Startup(IConfiguration config)
        {
            // Use JSON property names in validation.
            ValidationArgs.DefaultUseJsonNames = true;

            // Load the cache policies.
            CachePolicyManager.SetFromCachePolicyConfig(config.GetSection("BeefCaching").Get <CachePolicyConfig>());
            CachePolicyManager.StartFlushTimer(CachePolicyManager.TenMinutes, CachePolicyManager.FiveMinutes);

            // Register the ReferenceData provider.
            RefData.ReferenceDataManager.Register(new ReferenceDataProvider());

            // Register the database.
            Database.Register(() => new Database(WebApiStartup.GetConnectionString(config, "BeefDemo")));
            Beef.Data.Database.DatabaseInvoker.Default = new Beef.Data.Database.SqlRetryDatabaseInvoker();

            // Register the DocumentDb/CosmosDb client.
            CosmosDb.Register(() =>
            {
                var cs = config.GetSection("CosmosDb");
                return(new CosmosDb(new Cosmos.CosmosClient(cs.GetValue <string>("EndPoint"), cs.GetValue <string>("AuthKey")), cs.GetValue <string>("Database")));
            });

            // Register the test OData services.
            TestOData.Register(() => new TestOData(new Uri(WebApiStartup.GetConnectionString(config, "TestOData"))));
            TripOData.Register(() => new TripOData(new Uri(WebApiStartup.GetConnectionString(config, "TripOData"))));

            // Default the page size.
            PagingArgs.DefaultTake = config.GetValue <int>("BeefDefaultPageSize");

            // Configure the Service Agents from the configuration and register.
            var sac = config.GetSection("BeefServiceAgents").Get <WebApiServiceAgentConfig>();

            sac?.RegisterAll();

            // Set up the event publishing to event hubs.
            if (config.GetValue <bool>("EventHubPublishing"))
            {
                var ehc = EventHubClient.CreateFromConnectionString(config.GetValue <string>("EventHubConnectionString"));
                ehc.RetryPolicy = RetryPolicy.Default;
                var ehp = new EventHubPublisher(ehc);
                Event.Register((events) => ehp.Publish(events));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// The configure method called by the runtime; use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
        /// <param name="env">The <see cref="IHostingEnvironment"/>.</param>
        /// <param name="config">The <see cref="IConfiguration"/>.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        /// <param name="clientFactory">The <see cref="IHttpClientFactory"/>.</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration config, ILoggerFactory loggerFactory, IHttpClientFactory clientFactory)
        {
            // Configure the logger.
            _logger = loggerFactory.CreateLogger("Logging");
            Logger.RegisterGlobal((largs) => WebApiStartup.BindLogger(_logger, largs));

            // Register the HttpClientCreate so it uses the factory.
            WebApiServiceAgentManager.RegisterHttpClientCreate((rd) =>
            {
                var hc         = clientFactory.CreateClient(rd.BaseAddress.AbsoluteUri);
                hc.BaseAddress = rd.BaseAddress;
                return(hc);
            });

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Company.AppName");
            });

            // Override the exception handling.
            var includeExceptionInInternalServerError = config.GetValue <bool>("BeefIncludeExceptionInInternalServerError");

            app.UseExceptionHandler(c => WebApiStartup.ExceptionHandler(c, includeExceptionInInternalServerError));

            // Configure the ExecutionContext for the request.
            app.UseExecutionContext((context, ec) =>
            {
                ec.Username  = context.User.Identity.Name ?? "Anonymous";
                ec.Timestamp = DateTime.Now;
            });

            app.UseMvc();
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates the <see cref="IWebHostBuilder"/> using the <i>Beef</i> <see cref="WebApiStartup"/> capability to create the host with the underlying configuration probing.
 /// </summary>
 /// <param name="args">The startup arguments.</param>
 /// <returns>The <see cref="IWebHostBuilder"/>.</returns>
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebApiStartup.CreateWebHost <Startup>(args, "Hr");
Exemplo n.º 12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add the core beef services.
            services.AddBeefExecutionContext()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(_config.GetSection("BeefCaching").Get <CachePolicyConfig>())
            .AddBeefWebApiServices()
            .AddBeefGrpcServiceServices()
            .AddBeefBusinessServices();

            // Add the data sources as singletons for dependency injection requirements.
            services.AddBeefDatabaseServices(() => new Database(WebApiStartup.GetConnectionString(_config, "BeefDemo")))
            .AddBeefEntityFrameworkServices <EfDbContext, EfDb>()
            .AddBeefCosmosDbServices <CosmosDb>(_config.GetSection("CosmosDb"))
            .AddSingleton <ITestOData>(_ => new TestOData(new Uri(WebApiStartup.GetConnectionString(_config, "TestOData"))))
            .AddSingleton <ITripOData>(_ => new TripOData(new Uri(WebApiStartup.GetConnectionString(_config, "TripOData"))));

            // Add the generated reference data services for dependency injection requirements.
            services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services for dependency injection requirements.
            services.AddGeneratedManagerServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add event publishing.
            var ehcs = _config.GetValue <string>("EventHubConnectionString");

            if (!string.IsNullOrEmpty(ehcs))
            {
                services.AddBeefEventHubEventPublisher(ehcs);
            }
            else
            {
                services.AddBeefNullEventPublisher();
            }

            // Add services; note Beef requires NewtonsoftJson.
            services.AddControllers().AddNewtonsoftJson();
            services.AddGrpc();
            services.AddHealthChecks();
            services.AddHttpClient();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Beef (Business Entity Execution Framework) Demo API", Version = "v1"
                });

                var xmlName = $"{Assembly.GetEntryAssembly().GetName().Name}.xml";
                var xmlFile = Path.Combine(AppContext.BaseDirectory, xmlName);
                if (File.Exists(xmlFile))
                {
                    c.IncludeXmlComments(xmlFile);
                }
            });

            services.AddSwaggerGenNewtonsoftSupport();
        }
Exemplo n.º 13
0
        /// <summary>
        /// The configure services method called by the runtime; use this method to add services to the container.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            // Add the core beef services.
            services.AddBeefExecutionContext()
            .AddBeefTextProviderAsSingleton()
            .AddBeefSystemTime()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(_config.GetSection("BeefCaching").Get <CachePolicyConfig>())
            .AddBeefWebApiServices()
            .AddBeefBusinessServices();

            // Add the beef database services (scoped per request/connection).
            services.AddBeefDatabaseServices(() => new HrDb(WebApiStartup.GetConnectionString(_config, "Database")));

            // Add the beef entity framework services (scoped per request/connection).
            services.AddBeefEntityFrameworkServices <HrEfDbContext, HrEfDb>();

            // Add the generated reference data services.
            services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services.
            services.AddGeneratedManagerServices()
            .AddGeneratedValidationServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add event publishing services.
            var ehcs = _config.GetValue <string>("EventHubConnectionString");

            if (!string.IsNullOrEmpty(ehcs))
            {
                services.AddBeefEventHubEventProducer(new EventHubProducerClient(ehcs));
            }
            else
            {
                services.AddBeefNullEventPublisher();
            }

            // Add transactional event outbox services.
            services.AddGeneratedDatabaseEventOutbox();
            services.AddBeefDatabaseEventOutboxPublisherService();

            // Add AutoMapper services via Assembly-based probing for Profiles.
            services.AddAutoMapper(Beef.Mapper.AutoMapperProfile.Assembly, typeof(EmployeeData).Assembly);

            // Add additional services; note Beef requires NewtonsoftJson.
            services.AddControllers().AddNewtonsoftJson();
            services.AddHealthChecks();
            services.AddHttpClient();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My.Hr API", Version = "v1"
                });

                var xmlName = $"{Assembly.GetEntryAssembly()!.GetName().Name}.xml";
                var xmlFile = Path.Combine(AppContext.BaseDirectory, xmlName);
                if (File.Exists(xmlFile))
                {
                    c.IncludeXmlComments(xmlFile);
                }
            });

            services.AddSwaggerGenNewtonsoftSupport();
        }
Exemplo n.º 14
0
 public void Configuration(IAppBuilder appBuilder)
 {
     AuthStartup.ConfigureAuth(appBuilder);
     WebApiStartup.StartWebApi(appBuilder);
 }
Exemplo n.º 15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add the core beef services.
            services.AddBeefExecutionContext()
            .AddBeefSystemTime()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(_config.GetSection("BeefCaching").Get <CachePolicyConfig>())
            .AddBeefWebApiServices()
            .AddBeefGrpcServiceServices()
            .AddBeefBusinessServices()
            .AddBeefTextProviderAsSingleton();

            // Add the data sources as singletons for dependency injection requirements.
            services.AddBeefDatabaseServices(() => new Database(WebApiStartup.GetConnectionString(_config, "BeefDemo")))
            .AddBeefEntityFrameworkServices <EfDbContext, EfDb>()
            .AddBeefCosmosDbServices <CosmosDb>(_config.GetSection("CosmosDb"))
            .AddSingleton <ITestOData>(_ => new TestOData(new Uri(WebApiStartup.GetConnectionString(_config, "TestOData"))))
            .AddSingleton <ITripOData>(_ => new TripOData(new Uri(WebApiStartup.GetConnectionString(_config, "TripOData"))));

            // Add the generated reference data services for dependency injection requirements.
            services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services for dependency injection requirements.
            services.AddGeneratedManagerServices()
            .AddGeneratedValidationServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add event publishing.
            var ehcs = _config.GetValue <string>("EventHubConnectionString");
            var sbcs = _config.GetValue <string>("ServiceBusConnectionString");

            if (!string.IsNullOrEmpty(sbcs))
            {
                services.AddBeefEventHubEventProducer(new EventHubProducerClient(ehcs));
            }
            else if (!string.IsNullOrEmpty(sbcs))
            {
                services.AddBeefServiceBusSender(new ServiceBusClient(sbcs));
            }
            else
            {
                services.AddBeefNullEventPublisher();
            }

            // Add identifier generator services.
            services.AddSingleton <IGuidIdentifierGenerator, GuidIdentifierGenerator>()
            .AddSingleton <IStringIdentifierGenerator, StringIdentifierGenerator>();

            // Add event outbox services.
            services.AddGeneratedDatabaseEventOutbox();
            services.AddBeefDatabaseEventOutboxPublisherService();

            // Add custom services; in this instance to allow it to call itself for testing purposes.
            services.AddHttpClient("demo", c => c.BaseAddress = new Uri(_config.GetValue <string>("DemoServiceAgentUrl")));
            services.AddScoped <Common.Agents.IDemoWebApiAgentArgs>(sp => new Common.Agents.DemoWebApiAgentArgs(sp.GetService <System.Net.Http.IHttpClientFactory>().CreateClient("demo")));
            services.AddScoped <Common.Agents.IPersonAgent, Common.Agents.PersonAgent>();

            // Add services; note Beef requires NewtonsoftJson.
            services.AddAutoMapper(Mapper.AutoMapperProfile.Assembly, typeof(Beef.Demo.Common.Grpc.Transformers).Assembly, typeof(ContactData).Assembly);
            services.AddControllers().AddNewtonsoftJson();
            services.AddGrpc();
            services.AddHealthChecks();
            services.AddHttpClient();

            // Set up services for calling http://api.zippopotam.us/.
            services.AddHttpClient("zippo", c => c.BaseAddress = new Uri(_config.GetValue <string>("ZippoAgentUrl")));
            services.AddScoped <IZippoAgentArgs>(sp => new ZippoAgentArgs(sp.GetService <System.Net.Http.IHttpClientFactory>().CreateClient("zippo")));
            services.AddScoped <IZippoAgent, ZippoAgent>();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Beef (Business Entity Execution Framework) Demo API", Version = "v1"
                });

                var xmlName = $"{Assembly.GetEntryAssembly().GetName().Name}.xml";
                var xmlFile = Path.Combine(AppContext.BaseDirectory, xmlName);
                if (File.Exists(xmlFile))
                {
                    c.IncludeXmlComments(xmlFile);
                }
            });

            services.AddSwaggerGenNewtonsoftSupport();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Main startup using the <i>Beef</i> <see cref="WebApiStartup"/> capability to build the host and underlying configuration probing.
 /// </summary>
 /// <param name="args">The startup arguments.</param>
 public static void Main(string[] args) => WebApiStartup.BuildWebHost <Startup>(args, "AppName").Run();
Exemplo n.º 17
0
        /// <summary>
        /// The configure services method called by the runtime; use this method to add services to the container.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            // Add the core beef services.
            services.AddBeefExecutionContext()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(_config.GetSection("BeefCaching").Get <CachePolicyConfig>())
            .AddBeefWebApiServices()
            .AddBeefBusinessServices();

#if (implement_database || implement_entityframework)
            // Add the beef database services (scoped per request/connection).
            services.AddBeefDatabaseServices(() => new AppNameDb(WebApiStartup.GetConnectionString(_config, "Database")));
#endif
#if (implement_entityframework)
            // Add the beef entity framework services (scoped per request/connection).
            services.AddBeefEntityFrameworkServices <AppNameEfDbContext, AppNameEfDb>();
#endif
#if (implement_cosmos)
            // Add the beef cosmos services (singleton).
            services.AddBeefCosmosDbServices <AppNameCosmosDb>(_config.GetSection("CosmosDb"));
#endif
            // Add the generated reference data services.
            services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services.
            services.AddGeneratedManagerServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add event publishing services.
            var ehcs = _config.GetValue <string>("EventHubConnectionString");
            if (!string.IsNullOrEmpty(ehcs))
            {
                services.AddBeefEventHubEventPublisher(ehcs);
            }
            else
            {
                services.AddBeefNullEventPublisher();
            }

            // Add additional services; note Beef requires NewtonsoftJson.
            services.AddControllers().AddNewtonsoftJson();
            services.AddHealthChecks();
            services.AddHttpClient();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Company.AppName API", Version = "v1"
                });

                var xmlName = $"{Assembly.GetEntryAssembly()!.GetName().Name}.xml";
                var xmlFile = Path.Combine(AppContext.BaseDirectory, xmlName);
                if (File.Exists(xmlFile))
                {
                    c.IncludeXmlComments(xmlFile);
                }
            });

            services.AddSwaggerGenNewtonsoftSupport();
        }
Exemplo n.º 18
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     WebApiStartup.Configure(app, env);
 }
Exemplo n.º 19
0
        /// <summary>
        /// The configure services method called by the runtime; use this method to add services to the container.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            // Add the core beef services.
            services.AddBeefExecutionContext()
            .AddBeefTextProviderAsSingleton()
            .AddBeefSystemTime()
            .AddBeefRequestCache()
            .AddBeefCachePolicyManager(_config.GetSection("BeefCaching").Get <CachePolicyConfig>())
            .AddBeefWebApiServices()
            .AddBeefBusinessServices();

#if (implement_database || implement_entityframework)
            // Add the beef database services (scoped per request/connection).
            services.AddBeefDatabaseServices(() => new AppNameDb(WebApiStartup.GetConnectionString(_config, "Database")));
#endif
#if (implement_entityframework)
            // Add the beef entity framework services (scoped per request/connection).
            services.AddBeefEntityFrameworkServices <AppNameEfDbContext, AppNameEfDb>();
#endif
#if (implement_cosmos)
            // Add the beef cosmos services (singleton).
            services.AddBeefCosmosDbServices <AppNameCosmosDb>(_config.GetSection("CosmosDb"));
#endif
#if (implement_httpagent)
            // Add the HTTP agent services.
            services.AddHttpClient("Xxx", c => c.BaseAddress = new Uri(_config.GetValue <string>("XxxAgentUrl")));
            services.AddScoped <IXxxAgentArgs>(sp => new XxxAgentArgs(sp.GetService <IHttpClientFactory>().CreateClient("Xxx")));
            services.AddScoped <IXxxAgent, XxxAgent>();
#endif
            // Add the generated reference data services.
            services.AddGeneratedReferenceDataManagerServices()
            .AddGeneratedReferenceDataDataSvcServices()
            .AddGeneratedReferenceDataDataServices();

            // Add the generated entity services.
            services.AddGeneratedManagerServices()
            .AddGeneratedValidationServices()
            .AddGeneratedDataSvcServices()
            .AddGeneratedDataServices();

            // Add GUID identifier generator service.
            services.AddSingleton <IGuidIdentifierGenerator, GuidIdentifierGenerator>();

#if (implement_database || implement_entityframework)
            // Add transactional event outbox services.
            services.AddGeneratedDatabaseEventOutbox();
            services.AddBeefDatabaseEventOutboxPublisherService();
#endif
            // Add event publishing services.
            var sbcs = _config.GetValue <string>("ServiceBusConnectionString");
            if (!string.IsNullOrEmpty(sbcs))
            {
                services.AddBeefServiceBusSender(new ServiceBusClient(sbcs));
            }
            else
            {
                services.AddBeefNullEventPublisher();
            }

            // Add AutoMapper services via Assembly-based probing for Profiles.
            services.AddAutoMapper(Beef.Mapper.AutoMapperProfile.Assembly, typeof(PersonData).Assembly);

            // Add additional services; note Beef requires NewtonsoftJson.
            services.AddControllers().AddNewtonsoftJson();
            services.AddHealthChecks();
            services.AddHttpClient();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Company.AppName API", Version = "v1"
                });

                var xmlName = $"{Assembly.GetEntryAssembly()!.GetName().Name}.xml";
                var xmlFile = Path.Combine(AppContext.BaseDirectory, xmlName);
                if (File.Exists(xmlFile))
                {
                    c.IncludeXmlComments(xmlFile);
                }
            });

            services.AddSwaggerGenNewtonsoftSupport();
        }