Using models/database with controllers from plugins

May 14, 2014 at 8:38 PM
It is not straight forward on how to do this.
May 14, 2014 at 9:29 PM
Edited May 15, 2014 at 12:24 AM
The only major thing to keep an eye out for is visibility of models. If you have a Model class embedded directly in your web site project, it will not be visible to the plugin projects.

Plugin Projects should NEVER make a reference to the website project.

It is typically a good idea to move all Model classes into a separate class library project (dll). That way the web site and the plugin projects can all reference the Model class library and share the classes.

If a plugin has its own Model, it can keep the Model classes in its Model folder and use them with its views with no issues.

Database access from within a controller within the plugin would be no different. You can use LINQ and Entity Framework in your plugin. The main issue to watch out for is that typically connection strings are stored in the web site's web.config.

For unit testing, you can have an app.config in the plugin directory that also has its own connection string info that will be used when testing in the unit test environment.
May 16, 2014 at 12:20 PM
Thanks for the info. It was really helpful. I have put the required models in each plugin. I find this to be the easiest.
May 16, 2014 at 9:55 PM
I would not duplicate a class from one plugin to another. If a given Model is used by multiple plugins, put it in a Models project that all the plugin projects can reference.