1

I cant really get my head around one of the features i have to implement. Customers can have a bunch of addons which they pay for (list of addons is inside the db table). I have to implement functionality which only show plugins which customer had payed for.

I know that i can create a bunch of if statements inside the views, but its feels like it would be a bit "hacky" solution which would be a pain to work on.

Whats the right way to implement such functionality?

6
  • 1
    MEF (msdn.microsoft.com/en-us/library/dd460648%28v=vs.110%29.aspx)? Or, if you know that plugins are all written in advance, just control levels of access... Commented Feb 8, 2015 at 0:26
  • You need to show some code. Sounds like you view model for the customer just needs a property IEnumerable<addons> that you populate in the controller based on the customer ID, then use a loop in the view to display them Commented Feb 8, 2015 at 0:27
  • problem is that i want to have possibility to access IEnumerable<addons> from any ViewModel Commented Feb 8, 2015 at 0:32
  • @Timsen, No idea what your last comment means. If you don't show some code explaining what your doing, I doubt anyone can give an answer. Commented Feb 8, 2015 at 0:57
  • First, let's get some definitions here. What do you mean by "plugin" or "addon"? Do you actually mean "feature"? Or are these actual "extensions" that users can upload into the system, and it wasn't designed for them explicitly? Or are these simply "features" which you want to enable or disable for the user that are built in to the website by you the developer? Commented Feb 8, 2015 at 3:02

1 Answer 1

1

Since you are talking about features rather than plug-ins, I suggest you look at using AuthorizeAttribute with roles to control access to each feature and/or feature set.

public class FeatureController : Controller
{
    [Authorize(Roles = "Feature1")]
    public ActionResult Feature1()
    {
        // Implement feature here...

        return View();
    }

    [Authorize(Roles = "Feature1")]
    [HttpPost]
    public ActionResult Feature1(Model model)
    {
        // Implement feature here...

        return View();
    }

    [Authorize(Roles = "Feature2")]
    public ActionResult Feature2()
    {
        // Implement feature here...

        return View();
    }

    // Other features...
}

Then any user who is in the Feature1 role will have access to Feature1, the Feature2 role will have access to Feature2, etc.

You could combine AuthorizeAttribute with MvcSiteMapProvider's security trimming feature to make menu items that are only visible when the user is in the appropriate role.

Full Disclosure: I am a major contributor of MvcSiteMapProvider.

Sign up to request clarification or add additional context in comments.

1 Comment

What i did, was adding a new Area for each (plugin/feature) and create custom ActionFilter for each of them, so basicly same approach as you suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.