Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including the word Features in your project namespace breaks conventions #27

Closed
seangwright opened this issue Jun 3, 2018 · 2 comments

Comments

@seangwright
Copy link
Contributor

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

mvc-feature-folders-project-naming-convention-routing-error

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?

@OdeToCode
Copy link
Owner

Yes, I think the best change would be in the documentation.

@seangwright
Copy link
Contributor Author

I can PR this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants