Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.Configure <CookiePolicyOptions>(options =>
                {
                    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                    options.CheckConsentNeeded    = context => true;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                });

                services.AddMvc(opt => { opt.EnableEndpointRouting = true; });
                services.AddControllersWithViews().AddRazorRuntimeCompilation();

                services.AddControllers();
                services.AddRazorPages();
                services.AddCors();
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
                services.AddTransient <IPrincipal>(provider => provider.GetService <IHttpContextAccessor>().HttpContext.User);

                // APPSETTINGS
                var appSettings = AppSettingsBuilder.Build();
                services.AddSingleton(x => appSettings);

                AddBusinesLogic(services, Configuration, _env, appSettings);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Adds an <see cref="IConfigurationSource"/> for app settings to the given <see cref="IConfigurationBuilder"/>.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        /// <param name="buildAction">The action to build app settings.</param>
        /// <returns>The configuration builder.</returns>
        /// <remarks>
        /// This extension provides a simple way to add default values as well as descriptions for app settings
        /// directly into an application. The source for these is a simple in-memory collection, and additional
        /// key/value pairs are added so that the initial value and descriptions of these settings can still be
        /// retrieved even if the settings themselves get overridden by another configuration source.
        /// </remarks>
        public static IConfigurationBuilder AddAppSettings(this IConfigurationBuilder configurationBuilder, Action <IAppSettingsBuilder> buildAction)
        {
            IAppSettingsBuilder appSettingsBuilder = new AppSettingsBuilder();

            buildAction(appSettingsBuilder);

            IEnumerable <KeyValuePair <string, string> > appSettings = appSettingsBuilder.Build();

            configurationBuilder.AddInMemoryCollection(appSettings);
            return(configurationBuilder);
        }
Пример #3
0
        public void AppSettingIsAddForEverySettingNode()
        {
            AppSettingsNode settingsNode = new AppSettingsNode();

            base.ApplicationNode.AddNode(settingsNode);

            settingsNode.AddNode(new AppSettingNode("key", "value"));

            AppSettingsBuilder settingsBuilder = new AppSettingsBuilder(settingsNode);
            AppSettingsSection settingsSection = settingsBuilder.Build();

            Assert.IsNotNull(settingsSection);
            Assert.AreEqual(1, settingsSection.Settings.Count);
            Assert.AreEqual("key", settingsSection.Settings.AllKeys[0]);
            Assert.AreEqual("value", settingsSection.Settings["key"].Value);
        }