示例#1
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();
        }
示例#2
0
文件: Startup.cs 项目: edjo23/Beef
        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));
            }
        }