public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddCaching(); services.AddSession(); services.AddMvc(); services.AddSingleton<PassThroughAttribute>(); services.AddSingleton<UserNameService>(); services.AddTransient<ITestService, TestService>(); services.ConfigureMvc(options => { options.Filters.Add(typeof(PassThroughAttribute), order: 17); options.AddXmlDataContractSerializerFormatter(); options.Filters.Add(new FormatFilterAttribute()); }); #if DNX451 // Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine // but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment. // Functional tests update that service but not in the static provider. var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>(); var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json"); // Set up configuration sources. var configuration = new Configuration() .AddJsonFile(configurationPath) .AddEnvironmentVariables(); string diSystem; if (configuration.TryGet("DependencyInjection", out diSystem) && diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase)) { _autoFac = true; services.ConfigureRazorViewEngine(options => { var expander = new LanguageViewLocationExpander( context => context.HttpContext.Request.Query["language"]); options.ViewLocationExpanders.Insert(0, expander); }); // Create the autofac container var builder = new ContainerBuilder(); // Create the container and use the default application services as a fallback AutofacRegistration.Populate( builder, services); builder.RegisterModule<MonitoringModule>(); var container = builder.Build(); return container.Resolve<IServiceProvider>(); } else #endif { return services.BuildServiceProvider(); } }
public void ExpandViewLocations_SpecificLocale( LanguageViewLocationExpanderFormat format, IEnumerable <string> viewLocations, IEnumerable <string> expectedViewLocations) { // Arrange var viewLocationExpanderContext = new ViewLocationExpanderContext( new ActionContext(), "testView", "test-controller", "", null, false); var languageViewLocationExpander = new LanguageViewLocationExpander(format); viewLocationExpanderContext.Values = new Dictionary <string, string>(); viewLocationExpanderContext.Values["language"] = "en-GB"; // Act var expandedViewLocations = languageViewLocationExpander.ExpandViewLocations( viewLocationExpanderContext, viewLocations); // Assert Assert.Equal(expectedViewLocations, expandedViewLocations); }
// Set up application services public void ConfigureServices(IServiceCollection services) { // Add MVC services to the services container services.AddMvc(); services.AddTransient<InjectedHelper>(); services.AddTransient<TaskReturningService>(); services.AddTransient<FrameworkSpecificHelper>(); services.Configure<RazorViewEngineOptions>(options => { var expander = new LanguageViewLocationExpander( context => context.HttpContext.Request.Query["language-expander-value"]); options.ViewLocationExpanders.Add(expander); options.ViewLocationExpanders.Add(new CustomPartialDirectoryViewLocationExpander()); }); }
public void ExpandViewLocations_NullContextValue(IEnumerable <string> viewLocations) { // Arrange var viewLocationExpanderContext = new ViewLocationExpanderContext( new ActionContext(), "testView", "test-controller", "test-area", null, false); var languageViewLocationExpander = new LanguageViewLocationExpander(); viewLocationExpanderContext.Values = new Dictionary <string, string>(); // Act var expandedViewLocations = languageViewLocationExpander.ExpandViewLocations( viewLocationExpanderContext, viewLocations); // Assert Assert.Equal(viewLocations, expandedViewLocations); }
// Set up application services public void ConfigureServices(IServiceCollection services) { // Add MVC services to the services container services.AddMvc(); services.AddTransient<InjectedHelper>(); services.AddTransient<TaskReturningService>(); services.AddTransient<FrameworkSpecificHelper>(); services.Configure<RazorViewEngineOptions>(options => { var expander = new LanguageViewLocationExpander( context => context.HttpContext.Request.Query["language-expander-value"]); options.ViewLocationExpanders.Add(expander); options.ViewLocationExpanders.Add(new CustomPartialDirectoryViewLocationExpander()); }); services.ConfigureMvc(options => { options.HtmlHelperOptions.ClientValidationEnabled = false; options.HtmlHelperOptions.Html5DateRenderingMode = Microsoft.AspNet.Mvc.Rendering.Html5DateRenderingMode.Rfc3339; options.HtmlHelperOptions.IdAttributeDotReplacement = "!"; options.HtmlHelperOptions.ValidationMessageElement = "validationMessageElement"; options.HtmlHelperOptions.ValidationSummaryMessageElement = "validationSummaryElement"; }); }