/// <summary>
        ///     Use feature folders with custom options
        /// </summary>
        public static IMvcBuilder AddFeatureFolders(this IMvcBuilder services, FeatureFolderOptions options)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (options == null)
            {
                throw new ArgumentException(nameof(options));
            }

            var expander = new FeatureViewLocationExpander(options);

            services.AddMvcOptions(o => o.Conventions.Add(new FeatureControllerModelConvention(options)))
            .AddRazorOptions(o =>
            {
                o.ViewLocationFormats.Clear();
                o.ViewLocationFormats.Add(options.FeatureNamePlaceholder + @"\{0}.cshtml");
                o.ViewLocationFormats.Add(options.FeatureFolderName + @"\Shared\{0}.cshtml");
                o.ViewLocationFormats.Add(options.DefaultViewLocation);

                o.ViewLocationExpanders.Add(expander);
            });

            return(services);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            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;
            });

            var featureFolderOptions = new FeatureFolderOptions();

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddFeatureFolders(featureFolderOptions)
            .WithRazorPagesRoot($"/{featureFolderOptions.FeatureFolderName}")
            .AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining <Startup>(); });
            services.AddAutoMapper(typeof(Startup));
            services.AddMediatR(typeof(Startup));
            services.AddDbContext <TotemContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("Database")));

            services.AddScoped <TesterService>();

            services.Configure <EmailSettings>(Configuration.GetSection(nameof(EmailSettings)));
            services.AddScoped <IEmailSender, EmailSender>();
        }
        public void CanBuildPathFromControllerNamespace(Type controller, string expected)
        {
            var options        = new FeatureFolderOptions();
            var service        = new FeatureControllerModelConvention(options);
            var controllerType = controller.GetTypeInfo();
            var attributes     = new List <string>();
            var model          = new ControllerModel(controllerType, attributes);

            service.Apply(model);

            Assert.AreEqual(expected, model.Properties["feature"]);
        }
        public void Apply_WhenNamespaceHasFolderName_ShouldReturnPath(Type controller, string expectedPath)
        {
            var options        = new FeatureFolderOptions();
            var service        = new FeatureFolderControllerModelConvention(options);
            var controllerType = controller.GetTypeInfo();
            var attributes     = new List <string>();
            var model          = new ControllerModel(controllerType, attributes);

            service.Apply(model);

            var path = model.Properties[Constants.ControllerPropertyKey];

            Assert.Equal(path, expectedPath);
        }
        public void CanUseCustomDerivationStrategy()
        {
            var options = new FeatureFolderOptions()
            {
                DeriveFeatureFolderName = c => @"Features\Foo"
            };
            var service        = new FeatureControllerModelConvention(options);
            var controllerType = typeof(ManageUsersController).GetTypeInfo();
            var attributes     = new List <string>();
            var model          = new ControllerModel(controllerType, attributes);

            service.Apply(model);

            Assert.AreEqual(@"Features\Foo", model.Properties["feature"]);
        }
        public void Apply_WhenNamespaceDontHasFolderName_ShouldReturnEmptyString(Type controller)
        {
            var options = new FeatureFolderOptions()
            {
                FeatureFolderName = "SomeFolder"
            };
            var service        = new FeatureFolderControllerModelConvention(options);
            var controllerType = controller.GetTypeInfo();
            var attributes     = new List <string>();
            var model          = new ControllerModel(controllerType, attributes);

            service.Apply(model);

            var path = model.Properties[Constants.ControllerPropertyKey];

            Assert.Equal(String.Empty, path);
        }
Esempio n. 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            var featureOptions = new FeatureFolderOptions
            {
                DeriveFeatureFolderName = model =>
                {
                    var @namespace = model.ControllerType.Namespace;
                    var result     = @namespace.Split('.')
                                     .SkipWhile(s => s != "App")
                                     .Aggregate("", Path.Combine);

                    return(Path.Combine(result, model.RouteValues.Any() ? model.RouteValues.First().Key : "Index"));
                },
                FeatureFolderName = "App"
            };

            services.AddMvc().AddFeatureFolders(featureOptions);
            services.AddNodeServices();
        }
        /// <summary>
        /// Adds area feature folders to the application with format /Areas/{Area}/{RootFeatureFolder}/{Controller}/{View}.cshtml, /Areas/{Area}/{RootFeatureFolder}/{Controller}/Views/{View}.cshtml, /Areas/{Area}/{RootFeatureFolder}/Shared/Views/{View}.cshtml and /Areas/{Area}/Shared/Views/{View}.cshtml
        /// </summary>
        public static IMvcBuilder AddAreaFeatureFolders(this IMvcBuilder builder, Action <FeatureFolderOptions> setupAction = null)
        {
            var services = builder.Services;

            var options = new FeatureFolderOptions();

            if (setupAction != null)
            {
                setupAction(options);
            }

            services.Configure <RazorViewEngineOptions>(o =>
            {
                // {2} is area, {1} is controller,{0} is the action
                //o.AreaViewLocationFormats.Clear();
                o.AreaViewLocationFormats.Add("/Areas/{2}" + options.RootFeatureFolder + "/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Areas/{2}" + options.RootFeatureFolder + "/{1}/Views/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Areas/{2}" + options.RootFeatureFolder + "/Shared/Views/{0}" + RazorViewEngine.ViewExtension);

                foreach (var sharedViewFolder in options.SharedViewFolders)
                {
                    o.AreaViewLocationFormats.Add("/Areas/{2}" + options.RootFeatureFolder + "/Shared/Views/" + sharedViewFolder + "/{0}" + RazorViewEngine.ViewExtension);
                }

                o.AreaViewLocationFormats.Add("/Areas/Shared/Views/{0}" + RazorViewEngine.ViewExtension);

                foreach (var sharedViewFolder in options.SharedViewFolders)
                {
                    o.AreaViewLocationFormats.Add("/Areas/Shared/Views/" + sharedViewFolder + "/{0}" + RazorViewEngine.ViewExtension);
                }

                o.AreaViewLocationFormats.Add(options.RootFeatureFolder + "/Shared/Views/{0}" + RazorViewEngine.ViewExtension);

                foreach (var sharedViewFolder in options.SharedViewFolders)
                {
                    o.AreaViewLocationFormats.Add(options.RootFeatureFolder + "/Shared/Views/" + sharedViewFolder + "{0}" + RazorViewEngine.ViewExtension);
                }
            });

            return(builder);
        }
Esempio n. 9
0
        public void AddServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IAccessTokenProvider, AccessTokenProvider>();
            services.AddSingleton <ICustomerAccessTokenProvider, CustomerAccessTokenProvider>();

            var featureOptions = new FeatureFolderOptions();

            services.AddMvc(options => options.Filters.Add(typeof(ReauthenticationRequiredFilter)))
            .AddFeatureFolders(featureOptions).AddRazorOptions(o => o.ViewLocationFormats.Add(featureOptions.FeatureNamePlaceholder + "/{1}/{0}.cshtml"));

            RegisterAuthorizationPolicies(services);
            RegisterMappers(services);

            services.AddDistributedRedisCache(redisCacheOptions =>
            {
                redisCacheOptions.Configuration = configuration["Redis:Configuration"];
                redisCacheOptions.InstanceName  = configuration["Redis:InstanceName"];
            });

            AddAuthentication(services, configuration);
        }
        public void AddServices(IServiceCollection services, IConfiguration configuration)
        {
            services.Configure <AuthenticationOptions>(configuration.GetSection("Authentication:AzureAd"));
            services.Configure <B2CAuthenticationOptions>(configuration.GetSection("Authentication:AzureAd:B2C"));
            services.Configure <B2CPolicies>(configuration.GetSection("Authentication:AzureAd:B2C:Policies"));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IAccessTokenProvider, AccessTokenProvider>();
            services.AddSingleton <ICustomerAccessTokenProvider, CustomerAccessTokenProvider>();

            var featureOptions = new FeatureFolderOptions();

            services.AddMvc().AddFeatureFolders(featureOptions).AddRazorOptions(o => o.ViewLocationFormats.Add(featureOptions.FeatureNamePlaceholder + "/{1}/{0}.cshtml"));

            RegisterAuthorizationPolicies(services);
            RegisterMappers(services);

            services.AddDistributedRedisCache(redisCacheOptions =>
            {
                redisCacheOptions.Configuration = configuration["Redis:Configuration"];
                redisCacheOptions.InstanceName  = configuration["Redis:InstanceName"];
            });
        }
Esempio n. 11
0
 /// <summary>
 /// Options to control the area feature folders
 /// </summary>
 /// <param name="options">Can read options from <see cref="Miru.Mvc.FeaturesFolder.FeatureFolderOptions"/> if non default options are chosen</param>
 public AreaFeatureFolderOptions(FeatureFolderOptions options)
 {
     AreaFolderName          = "Areas";
     DefaultAreaViewLocation = $@"Areas\{{2}}\{options.FeatureNamePlaceholder}\{{0}}.cshtml";
     FeatureFolderName       = options.FeatureFolderName;
 }