A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/OdeToCode/AddFeatureFolders/issues/27 below:

Including the word `Features` in your project namespace breaks conventions · Issue #27 · OdeToCode/AddFeatureFolders · GitHub

I created a new ASP.NET Core 2.1 MVC project and named the project ASPNETCoreMVC.Features.Web.

I added <PackageReference Include="OdeToCode.AddFeatureFolders" Version="2.0.1" /> to my .csproj.

When I run the app it says

An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
Features\Web\Features\Home\Index.cshtml
Features\Shared\Index.cshtml
\Features\Index\Home.cshtml

In this case I'd need to change FeatureFolderOptions.FeatureFolderName to something other than Features because

@namespace.Split('.')
	 .SkipWhile(s => s != _folderName)
	.Aggregate("", Path.Combine);

is going to stop too early and create the wrong folder path.

Here is an ugly solution

.AddFeatureFolders(new FeatureFolderOptions
{
    FeatureFolderName = "Features",
    DeriveFeatureFolderName = model =>
    {
        string assemblyNamespacePrefix = $"{typeof(Startup).Namespace}.";
        string @namespace = model
                .ControllerType
                .Namespace
                .Remove(0, assemblyNamespacePrefix.Length);

        string result = @namespace.Split('.')
                                .SkipWhile(s => s != "Features")
                                .Aggregate("", Path.Combine);

        return result;
    }
});

But maybe the best thing to do is add a disclaimer to the README.md that your feature folder name cannot be in the project namespace?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4