How to programatically register a RoleProvider in ASP.NET MVC 5?

Viewed 552

I've implemented a role provider using dependency injection technique. So as the class doesn't have a parameterless constructor (a repository is injected there), the usual web.config registration method doesn't work.

I was trying to register the provider manually in my Global.asax application start event like this, but I get a NotSupportedException stating that the Roles.Providers collection cannot be modified.

Roles.Providers.Clear();
Roles.Providers.Add(new RepositoryRoleProvider(new MyRepositoryFactory()));

What is the proper way to register a role provider without it having a parameterless constructor?

1 Answers
Related