Code Monkey home page Code Monkey logo

featuresviewengine's Introduction

Features View Engine

Description

Features View Engine is an ASP.NET MVC view engine which enables feature folder support. It resolves view paths using the controller's namespace.

Installation

Install using NuGet:

Install-Package FeaturesViewEngine

Configuration

Default configuration

There is a default view engine - DefaultControllerFeaturesViewEngine. Register this view engine on the application start (usually in Global.asax):

ViewEngines.Engines.Insert(0, new DefaultControllerFeaturesViewEngine());

This view engine will resolve views by the controller's namespace. In these locations:

%feature%/{0}.cshtml
%feature%/Views/{0}.cshtml
%feature%/Views/{1}{0}.cshtml

The %feature% placeholder will match the controller's namespace excluding an assembly name. For example, you have a controller in the namespace - MyAssembly.Web.Features.HomePage and the assembly name is - MyAssembly.Web. Then the %feature% placeholder will be replaced with path - ~/Features/HomePage.

NOTE: This view engine resolves only paths for views which have a controller. You should create a separate view engine for views which are rendered without a controller.

Custom paths

If you have a different convention for view path, then you can create a derived view engine from ControllerFeaturesViewEngine and define your paths. You can user DefaultControllerFeaturesViewEngine as a template:

public sealed class DefaultControllerFeaturesViewEngine : ControllerFeaturesViewEngine
{
    public DefaultControllerFeaturesViewEngine()
    {
        var paths = new[]
        {
            $"{FeaturePlaceholder}/{{0}}.cshtml",
            $"{FeaturePlaceholder}/Views/{{0}}.cshtml",
            $"{FeaturePlaceholder}/Views/{{1}}{{0}}.cshtml"
        };

        ViewLocationFormats = paths;
        PartialViewLocationFormats = paths;
    }
}

FeaturePlaceholder is a constant for %feature%.

Custom assembly name

Sometimes assembly name doesn't match the default namespace name. Then you should create a derived view engine from ControllerFeaturesViewEngine (see "Custom paths" section) and override NamespacePrefixToRemove method to return your namespace prefix to ignore.

Custom view path format

In some cases, it is useful to have a different view path format. For example, in a multisite environment, you might want to have different view paths for the same feature.

Then you can create a derived view engine (see "Custom paths" section) and override FormatViewPath method with your view path resolution logic.

featuresviewengine's People

Contributors

kaspars-ozols avatar klavs avatar marisks avatar

Stargazers

 avatar

featuresviewengine's Issues

Could not load file or assembly 'System.ValueTuple'

Package NuSpec does not define dependency on Sytem.ValueTuple package. When deployed to server with older .NET version, this causes problems.

Either need to add dependency or change code not to use ValueTuple type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.