示例#1
0
        public void Main(string[] args)
        {
            var config = new Configuration();

            if (File.Exists(HostingIniFile))
            {
                config.AddIniFile(HostingIniFile);
            }
            config.AddEnvironmentVariables();
            config.AddCommandLine(args);

            var serviceCollection = new ServiceCollection();

            serviceCollection.Add(HostingServices.GetDefaultServices(config));
            var services = serviceCollection.BuildServiceProvider(_serviceProvider);

            var appEnvironment = _serviceProvider.GetService <IApplicationEnvironment>();

            var context = new HostingContext()
            {
                Services        = services,
                Configuration   = config,
                ServerName      = config.Get("server"), // TODO: Key names
                ApplicationName = config.Get("app")     // TODO: Key names
                                  ?? appEnvironment.ApplicationName,
                EnvironmentName = config.Get("env") ?? "Development"
            };

            var engine = services.GetService <IHostingEngine>();

            if (engine == null)
            {
                throw new Exception("TODO: IHostingEngine service not available exception");
            }

            var appShutdownService = _serviceProvider.GetService <IApplicationShutdown>();

            if (appShutdownService == null)
            {
                throw new Exception("TODO: IApplicationShutdown service not available");
            }
            var shutdownHandle = new ManualResetEvent(false);

            var serverShutdown = engine.Start(context);

            appShutdownService.ShutdownRequested.Register(() =>
            {
                serverShutdown.Dispose();
                shutdownHandle.Set();
            });

            var ignored = Task.Run(() =>
            {
                Console.WriteLine("Started");
                Console.ReadLine();
                appShutdownService.RequestShutdown();
            });

            shutdownHandle.WaitOne();
        }
示例#2
0
        public void Configure(IBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();

            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                // Add MVC services to the services container
                services.AddMvc();
            });

            // Enable Browser Link support
            app.UseBrowserLink();

            // Add static files to the request pipeline
            app.UseStaticFiles();


            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
示例#3
0
        public void Configure(IBuilder app)
        {
            var configuration = new Configuration();

            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                services.Add(OptionsServices.GetDefaultServices());
                services.SetupOptions <BlobStorageOptions>(options =>
                {
                    options.ConnectionString = configuration.Get("ReversePackageSearch:BlobStorageConnection");
                });
                // Add MVC services to the services container
                services.AddMvc();
            });

            // Add static files
            app.UseStaticFiles(new StaticFileOptions {
                FileSystem = new PhysicalFileSystem("content")
            });
            // Add MVC to the request pipeline
            app.UseMvc();
        }
示例#4
0
        /// <summary>
        /// Sets up the DI container. Loads types dynamically (http://docs.autofac.org/en/latest/register/scanning.html)
        /// </summary>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            /* TODO: #10
             * services.AddCaching();
             * services.AddSession();
             *
             * services.ConfigureSession(o =>
             * {
             *      o.IdleTimeout = TimeSpan.FromMinutes(5);
             * });*/

            services.AddTransient <WopiAuthorizationAttribute>();

            // Autofac resolution
            var builder = new ContainerBuilder();

            // Configuration
            Configuration configuration = new Configuration();

            configuration.AddEnvironmentVariables();
            builder.RegisterInstance(configuration).As <IConfiguration>().SingleInstance();

            // File provider implementation
            var providerAssembly = configuration.Get("WopiFileProviderAssemblyName");
            var assembly         = AppDomain.CurrentDomain.Load(new AssemblyName(providerAssembly));

            builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces();

            builder.Populate(services);
            var container = builder.Build();

            return(container.Resolve <IServiceProvider>());
        }
示例#5
0
        public void Configure(IApplicationBuilder app)
        {
            var config = new Configuration();

            config.AddEnvironmentVariables();
            config.AddJsonFile("config.json");
            config.AddJsonFile("config.dev.json", true);
            config.AddUserSecrets();

            var password = config.Get("password");

            if (config.Get <bool>("RecreateDatabase"))
            {
                var context = app.ApplicationServices.GetService <Models.BlogDataContext>();
                context.Database.EnsureDeleted();
                System.Threading.Thread.Sleep(2000);
                context.Database.EnsureCreated();
            }


            if (config.Get <bool>("debug"))
            {
                app.UseErrorPage();
                app.UseRuntimeInfoPage();
            }
            else
            {
                app.UseErrorHandler("/home/error");
            }

            app.UseMvc(routes => routes.MapRoute(
                           "Default", "{controller=Home}/{action=Index}/{id?}"));

            app.UseFileServer();
        }
示例#6
0
        public void Configure(IBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                // Add MVC services to the services container
                services.AddMvc();
            });

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default", 
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
示例#7
0
        public void Configure(IApplicationBuilder app)
        {
            var config = new Configuration();

            config.AddEnvironmentVariables();
            config.AddJsonFile("config.json");
            config.AddJsonFile("config.dev.json", true);
            config.AddUserSecrets();

            var password = config.Get("password");


            if (config.Get <bool>("debug"))
            {
                app.UseErrorPage();
                app.UseRuntimeInfoPage();
            }
            else
            {
                app.UseErrorHandler("/home/error");
            }


            app.UseMvc(routes =>
                       routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}"));

            app.UseFileServer();
        }
示例#8
0
 public MyJasperApp()
 {
     // Set up the application configuration
     Configuration
     .AddEnvironmentVariables()
     .AddJsonFile("appsettings.json");
 }
示例#9
0
        public Startup(IHostingEnvironment env)
        {
            System.Console.WriteLine(env.EnvironmentName);

            var dt = new Models.DevTool();

            dt.toolName      = "Visual Studio Code";
            dt.twitterHandle = "@code";

            var    c     = new ClassLibrary.Customer("John", "Papa");
            var    fname = c.FirstName;
            string msg;

            msg = "why, hello there! hello back at ya!";

            logInfo("hello asp.net world! " + dt.toolName + " is the tool name");

            // Setup configuration sources.
            var configuration = new Configuration()
                                .AddJsonFile("config.json")
                                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsEnvironment("Development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                configuration.AddUserSecrets();
            }
            configuration.AddEnvironmentVariables();
            Configuration = configuration;
        }
示例#10
0
        private static IConfiguration CreateConfig(string[] args)
        {
            var config = new Configuration();

            config.AddEnvironmentVariables();
            return(config);
        }
示例#11
0
    public void Configure(IBuilder app)
    {
        app.UseServices(services =>
        {
            /* Adding IConfiguration as a service in the IoC to avoid instantiating Configuration again.
             * Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
             * then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
             */
            var configuration = new Configuration();
            configuration.AddJsonFile("LocalConfig.json");
            configuration.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
            services.AddInstance <IConfiguration>(configuration);

            //Add all MVC related services to IoC.
            services.AddMvc();

            /*Add all EF related services to IoC.*/
            services.AddEntityFramework().AddSqlServer();
            services.AddTransient <MusicStoreContext>();

            //Add all Identity related services to IoC.
            services.AddTransient <DbContext, ApplicationDbContext>();
            services.AddIdentity <ApplicationUser, IdentityRole>(s =>
            {
                s.AddEntity();
            });
            services.AddTransient <SignInManager <ApplicationUser> >();
        });


        /* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
         * Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
         */
        app.UseErrorPage(ErrorPageOptions.ShowAll);

        //Serves static files in the application.
        app.UseFileServer();

        app.UseCookieAuthentication(new CookieAuthenticationOptions()
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath          = new PathString("/Account/Login"),
        });

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                null,
                "{controller}/{action}",
                new { controller = "Home", action = "Index" });
        });

        //Populates the MusicStore sample data
        SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
        SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();

        //Creates a Store manager user who can manage the store.
        CreateAdminUser(app.ApplicationServices).Wait();
    }
示例#12
0
        public void Configure(IApplicationBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();

            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                // Add EF services to the services container and configure DbContext
                services.ConfigureDataContext(configuration);

                // Register MyShuttle dependencies
                services.ConfigureDependencies();


                //Add Identity services to the services container
                services.AddDefaultIdentity <MyShuttleContext, ApplicationUser, IdentityRole>(configuration);
                services.ConfigureCookieAuthentication(options =>
                {
                    options.LoginPath = new Microsoft.AspNet.Http.PathString("/Carrier/Login");
                });


                // Add MVC services to the services container
                services.AddMvc();

                services
                .AddSignalR(options =>
                {
                    options.Hubs.EnableDetailedErrors = true;
                });
            });

            // Enable Browser Link support
            app.UseBrowserLink();

            /* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
             * Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
             */
            app.UseErrorPage(ErrorPageOptions.ShowAll);

            // Add static files to the request pipeline
            app.UseStaticFiles();

            app.ConfigureSecurity();

            //Configure SignalR
            app.UseSignalR();

            // Add cookie-based authentication to the request pipeline

            // Add MVC to the request pipeline
            app.ConfigureRoutes();

            MyShuttleDataInitializer.InitializeDatabaseAsync(app.ApplicationServices).Wait();
        }
示例#13
0
    public void Configure(IBuilder app)
    {
        app.UseServices(services =>
        {
            /* Adding IConfiguration as a service in the IoC to avoid instantiating Configuration again.
             * Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources, 
             * then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
            */
            var configuration = new Configuration();
            configuration.AddJsonFile("LocalConfig.json");
            configuration.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
            services.AddInstance<IConfiguration>(configuration);

            //Add all MVC related services to IoC.
            services.AddMvc();

            /*Add all EF related services to IoC.*/
            services.AddEntityFramework().AddSqlServer();
            services.AddTransient<MusicStoreContext>();

            //Add all Identity related services to IoC. 
            services.AddTransient<DbContext, ApplicationDbContext>();
            services.AddIdentity<ApplicationUser, IdentityRole>(s =>
            {
                s.AddEntity();
            });
            services.AddTransient<SignInManager<ApplicationUser>>();
        });


        /* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
         * Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
         */
        app.UseErrorPage(ErrorPageOptions.ShowAll);

        //Serves static files in the application.
        app.UseFileServer();

        app.UseCookieAuthentication(new CookieAuthenticationOptions()
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
        });

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                null,
                "{controller}/{action}",
                new { controller = "Home", action = "Index" });
        });

        //Populates the MusicStore sample data
        SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
        SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();

        //Creates a Store manager user who can manage the store.
        CreateAdminUser(app.ApplicationServices).Wait();
    }
示例#14
0
        public void Configure(IApplicationBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                // Add EF services to the services container and configure DbContext
                services.ConfigureDataContext(configuration);

                // Register MyShuttle dependencies
                services.ConfigureDependencies();


                //Add Identity services to the services container
                services.AddDefaultIdentity<MyShuttleContext, ApplicationUser, IdentityRole>(configuration);
                services.ConfigureCookieAuthentication(options =>
                {
                    options.LoginPath = new Microsoft.AspNet.Http.PathString("/Carrier/Login");
                });


                // Add MVC services to the services container
                services.AddMvc();

                services
                    .AddSignalR(options =>
                    {
                        options.Hubs.EnableDetailedErrors = true;
                    });
            });

            // Enable Browser Link support
            app.UseBrowserLink();

            /* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
             * Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
             */
            app.UseErrorPage(ErrorPageOptions.ShowAll);

            // Add static files to the request pipeline
            app.UseStaticFiles();

            app.ConfigureSecurity();

            //Configure SignalR
            app.UseSignalR();

            // Add cookie-based authentication to the request pipeline

            // Add MVC to the request pipeline
            app.ConfigureRoutes();

            MyShuttleDataInitializer.InitializeDatabaseAsync(app.ApplicationServices).Wait();

        }
示例#15
0
        public void Configure(IApplicationBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();

            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                services.AddAssembly(this);

                // Add EF services to the services container
                services.AddEntityFramework()
                .AddSqlServer();

                // Configure DbContext
                services.SetupOptions <DbContextOptions>(options =>
                {
                    options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
                });

                //// Add Identity services to the services container
                //services.AddIdentitySqlServer<ApplicationDbContext, ApplicationUser>()
                //    .AddAuthentication();

                // Add MVC services to the services container
                services.AddMvc();

                services.AddTransient(typeof(IService1), typeof(Service1));
            });

            // Enable Browser Link support
            //app.UseBrowserLink();

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType,
                LoginPath          = new PathString("/Account/Login"),
            });

            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
示例#16
0
        public AppUsingConsul()
        {
            // In this case, we're expecting an environment
            // variable called "Consul.Port"
            Configuration.AddEnvironmentVariables();

            Settings.Alter <ConsulSettings>(ConfigureConsul);
        }
示例#17
0
        public MyJasperApp()
        {
            ServiceName = "My Jasper App";

            Configuration.AddEnvironmentVariables();

            Transports.ListenForMessagesFrom("durable://localhost:2111/incoming");
        }
示例#18
0
        public static void AddConfiguration(this IServiceCollection services)
        {
            Configuration configuration = new Configuration();

            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            services.AddInstance <IConfiguration>(configuration);
        }
示例#19
0
        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var configuration = new Configuration()
                                .AddJsonFile("config.json")
                                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            configuration.AddEnvironmentVariables();
            Configuration = configuration;
        }
示例#20
0
 public void Configure(IBuilder app)
 {
     var config = new Configuration();
     config.AddEnvironmentVariables();
     
     app.Run(async ctx => 
     {
         ctx.Response.ContentType = "text/plain";
         DumpConfig(ctx.Response, config);
     });
 }
示例#21
0
    public void Configure(IApplicationBuilder app)
    {
        var config = new Configuration();
        config.AddIniFile("Config.Sources.ini");
        config.AddEnvironmentVariables();

        app.Run(async ctx =>
        {
            ctx.Response.ContentType = "text/plain";
            await DumpConfig(ctx.Response, config);
        });
    }
示例#22
0
    public void Configure(IBuilder app)
    {
        var config = new Configuration();

        config.AddEnvironmentVariables();

        app.Run(async ctx =>
        {
            ctx.Response.ContentType = "text/plain";
            DumpConfig(ctx.Response, config);
        });
    }
示例#23
0
        public void Configure(IBuilder app)
        {
            // Enable Browser Link support
            app.UseBrowserLink();

            // Setup configuration sources
            var configuration = new Configuration();

            //configuration.AddIniFile("config.ini");
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            //app.Run(async context =>
            //{
            //    await context.Response.WriteAsync(configuration.Get("Data:Configuration"));
            //});

            app.Run(async context =>
            {
                var asm             = Assembly.Load(new AssemblyName("klr.host"));
                var assemblyVersion = asm.GetCustomAttribute <AssemblyInformationalVersionAttribute>();

                await context.Response.WriteAsync(assemblyVersion.InformationalVersion);
            });

            // Set up application services
            app.UseServices(services =>
            {
                // Add EF services to the services container
                services.AddEntityFramework().AddInMemoryStore();
                services.AddScoped <PersonContext>();

                // Add MVC services to the services container
                services.AddMvc();
            });

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
示例#24
0
        public MyAppWithSettings()
        {
            Configuration
            .AddEnvironmentVariables()
            .AddJsonFile("appSettings.json");

            Settings.With <MySettings>(_ =>
            {
                Transports.LightweightListenerAt(_.LightweightPort);

                Transports.ListenForMessagesFrom(_.DefaultListener);
            });
        }
        public Startup(IHostingEnvironment env)
        {
            var configuration = new Configuration()
                                .AddJsonFile("config.json")
                                .AddJsonFile($"config.{env.EnvironmentName}.json", true);

            if (env.IsEnvironment("Development"))
            {
                configuration.AddUserSecrets();
            }
            configuration.AddEnvironmentVariables();
            Configuration = configuration;
        }
示例#26
0
        public ConfigSetup()
        {
            // Make individual calls to AddXXX extension methods
            var config = new Configuration();

            config.AddJsonFile("config.json");
            config.AddEnvironmentVariables();

            // Fluent configuration
            var configFluent = new Configuration()
                               .AddJsonFile("config.json")
                               .AddEnvironmentVariables();
        }
示例#27
0
        public void Main(string[] args)
        {
            var config = new Configuration();

            if (File.Exists(HostingIniFile))
            {
                config.AddIniFile(HostingIniFile);
            }
            config.AddEnvironmentVariables();
            config.AddCommandLine(args);

            var services = HostingServices.Create(_serviceProvider, config)
                           .BuildServiceProvider();

            var appEnv     = services.GetRequiredService <IApplicationEnvironment>();
            var hostingEnv = services.GetRequiredService <IHostingEnvironment>();

            var context = new HostingContext()
            {
                Services        = services,
                Configuration   = config,
                ServerName      = config.Get("server"), // TODO: Key names
                ApplicationName = config.Get("app")     // TODO: Key names
                                  ?? appEnv.ApplicationName,
                EnvironmentName = hostingEnv.EnvironmentName,
            };

            var engine             = services.GetRequiredService <IHostingEngine>();
            var appShutdownService = _serviceProvider.GetRequiredService <IApplicationShutdown>();
            var shutdownHandle     = new ManualResetEvent(false);

            var serverShutdown = engine.Start(context);

            appShutdownService.ShutdownRequested.Register(() =>
            {
                serverShutdown.Dispose();
                shutdownHandle.Set();
            });

            var ignored = Task.Run(() =>
            {
                Console.WriteLine("Started");
                Console.ReadLine();
                appShutdownService.RequestShutdown();
            });

            shutdownHandle.WaitOne();
        }
示例#28
0
        public void Configure(IApplicationBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();

            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

            // Set up application services
            app.UseServices(services =>
            {
                // Add EF services to the services container
                services.AddEntityFramework()
                .AddSqlServer();

                // Configure DbContext
                services.SetupOptions <DbContextOptions>(options =>
                {
                    options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
                });



                // Add MVC services to the services container
                services.AddMvc();
            });

            // Enable Browser Link support
            app.UseBrowserLink();

            // Add static files to the request pipeline
            app.UseStaticFiles();



            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
示例#29
0
        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsEnvironment("Development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                configuration.AddUserSecrets();
            }
            configuration.AddEnvironmentVariables();
            Configuration = configuration;
        }
示例#30
0
        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var configuration = new Configuration()
                                .AddJsonFile("config.json")
                                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsEnvironment("Development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                configuration.AddUserSecrets();
            }
            configuration.AddEnvironmentVariables();
            Configuration = configuration;
        }
示例#31
0
文件: Startup.cs 项目: mschwa/Docs
        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var configuration = new Configuration()
                                .AddJsonFile("config.json")
                                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsEnvironment("Development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                configuration.AddUserSecrets();

                // This will expedite telemetry through pipeline,
                // allowing you to view results immediately
                configuration.AddApplicationInsightsSettings(developerMode: true);
            }
            configuration.AddEnvironmentVariables();
            Configuration = configuration;
        }
示例#32
0
    public void Configure(IBuilder app)
    {
        var config = new Configuration();
        config.AddIniFile("Config.Sources.ini");
        config.AddEnvironmentVariables();

        app.Run(async ctx =>
        {
            ctx.Response.ContentType = "text/plain";

            Func<String, String> formatKeyValue = key => "[" + key + "] " + config.Get(key) + "\r\n\r\n";
            await ctx.Response.WriteAsync(formatKeyValue("Services:One.Two"));
            await ctx.Response.WriteAsync(formatKeyValue("Services:One.Two:Six"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:DefaultConnecection:ConnectionString"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:DefaultConnecection:Provider"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:Inventory:ConnectionString"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:Inventory:Provider"));
            await ctx.Response.WriteAsync(formatKeyValue("PATH"));
            await ctx.Response.WriteAsync(formatKeyValue("COMPUTERNAME"));
        });
    }
示例#33
0
    public void Configure(IBuilder app)
    {
        var config = new Configuration();

        config.AddIniFile("Config.Sources.ini");
        config.AddEnvironmentVariables();

        app.Run(async ctx =>
        {
            ctx.Response.ContentType = "text/plain";

            Func <String, String> formatKeyValue = key => "[" + key + "] " + config.Get(key) + "\r\n\r\n";
            await ctx.Response.WriteAsync(formatKeyValue("Services:One.Two"));
            await ctx.Response.WriteAsync(formatKeyValue("Services:One.Two:Six"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:DefaultConnecection:ConnectionString"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:DefaultConnecection:Provider"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:Inventory:ConnectionString"));
            await ctx.Response.WriteAsync(formatKeyValue("Data:Inventory:Provider"));
            await ctx.Response.WriteAsync(formatKeyValue("PATH"));
            await ctx.Response.WriteAsync(formatKeyValue("COMPUTERNAME"));
        });
    }
示例#34
0
        /// <summary>
        /// Sets up the DI container. Loads types dynamically (http://docs.autofac.org/en/latest/register/scanning.html)
        /// </summary>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // Autofac resolution
            var builder = new ContainerBuilder();

            // Configuration
            Configuration configuration = new Configuration();

            configuration.AddEnvironmentVariables();
            builder.RegisterInstance(configuration).As <IConfiguration>().SingleInstance();

            // File provider implementation
            var providerAssembly = configuration.Get("WopiFileProviderAssemblyName");
            var assembly         = AppDomain.CurrentDomain.Load(new AssemblyName(providerAssembly));

            builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces();

            builder.Populate(services);
            var container = builder.Build();

            return(container.Resolve <IServiceProvider>());
        }
示例#35
0
        public void Configure(IBuilder app)
        {
            // Setup configuration sources
            var configuration = new Configuration();

            configuration.AddEnvironmentVariables();

            app.UseOwin();

            // Set up application services
            app.UseServices(services =>
            {                // Add MVC services to the services container
                services.AddMvc();
                services.SetupOptions <MvcOptions>(options => {
                    System.Diagnostics.Debug.WriteLine(options.OutputFormatters.Select(item => item.GetType().Name));

                    options.OutputFormatters.RemoveAt(0);
                });
            });

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                //routes.MapRoute(
                //    name: "default",
                //    template: "{controller}/{action}/{id?}",
                //    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });
        }
示例#36
0
        public void Configure(IBuilder app)
        {
            /* Adding IConfiguration as a service in the IoC to avoid instantiating Configuration again.
             * Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
             * then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
             */
            var configuration = new Configuration();

            configuration.AddJsonFile("LocalConfig.json");
            configuration.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.

            /* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
             * Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
             */
            app.UseErrorPage(ErrorPageOptions.ShowAll);

            app.UseServices(services =>
            {
                //If this type is present - we're on mono
                var runningOnMono = Type.GetType("Mono.Runtime") != null;

                // Add EF services to the services container
                if (runningOnMono)
                {
                    services.AddEntityFramework()
                    .AddInMemoryStore();
                }
                else
                {
                    services.AddEntityFramework()
                    .AddSqlServer();
                }

                services.AddScoped <MusicStoreContext>();

                // Configure DbContext
                services.SetupOptions <MusicStoreDbContextOptions>(options =>
                {
                    options.DefaultAdminUserName = configuration.Get("DefaultAdminUsername");
                    options.DefaultAdminPassword = configuration.Get("DefaultAdminPassword");
                    if (runningOnMono)
                    {
                        options.UseInMemoryStore();
                    }
                    else
                    {
                        options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
                    }
                });

                // Add Identity services to the services container
                services.AddIdentitySqlServer <MusicStoreContext, ApplicationUser>()
                .AddAuthentication();

                // Add MVC services to the services container
                services.AddMvc();
            });

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType,
                LoginPath          = new PathString("/Account/Login"),
            });

            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });

            //Populates the MusicStore sample data
            SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
        }
示例#37
0
        public Startup()
        {
            var config = new Configuration();

            config.AddEnvironmentVariables();
        }