IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
One of the most common patterns in programming is the Inversion of Control (IoC) design pattern. You can also use this pattern with ASP.NET MVC.
The advantages of using the IoC design pattern are the following:
In the following article you will learn how to use the Dependency Injection over the constructor of the controller. You will create a custom Feather widget for the Author dynamic type. You can download the whole Constructor injection sample from the GitHub repository and follow the procedure below.
Perform the following:
Name
JobTitle
Bio
IAuthorsService
AuthorsService
Ninject
NOTE: The AuthorsController constructor receives an IAuthorService type parameter, which you need to perform service calls inside the class. However, the AuthorsController class does not implement the default constructor (a constructor with no parameters) that any controller must have to work with ASP.NET MVC. Therefore, if you drag a widget implemented without a default constructor on a Sitefinity CMS page and view it on the frontend, an error similar to the following will be displayed: No paremeterless constructor defined for this object.
AuthorsController
IAuthorService
To display the widget correctly on the frontend, you need to inject the controller by creating a custom controller factory.
DefaultControllerFactory
FrontendControllerFactory
IKernel
InterfaceMappings
Global.asax
Bootstrapper
Bootstrapped
RESULT: As a result, you add a dependency injection for the controller of the Feather custom widget. Thus, you can continue working on the actions of the controller and implementing your views.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important