Esempio 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; 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());
        }
Esempio n. 2
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");
        }
Esempio n. 3
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.
            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 Microsoft.Azure.Cosmos.CosmosClient(cs.GetValue <string>("EndPoint"), cs.GetValue <string>("AuthKey")), cs.GetValue <string>("Database")));
            });
#endif
            // Register the ReferenceData provider.
            Beef.RefData.ReferenceDataManager.Register(new ReferenceDataProvider());
        }
Esempio n. 4
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();
        }
Esempio 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")));
            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));
            }
        }
Esempio n. 6
0
        public void Configure(IWebJobsBuilder builder)
        {
            var config = builder.GetConfiguration(typeof(Startup).Assembly, environmentVariablesPrefix: "Beef_");

            // 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(config.GetConnectionString("BeefDemo")));

            // 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")));
            });
        }