This IoC container provides a custom IPresenterFactory which utilizes http://ninject.org/ as the underlying framework.

This IPresenterFactory resides in the WebFormsMvp.Contrib.Ninject assembly, in the MvpPresenterKernel class.


The Ninject IPresenterFactory can be used like any other custom IPresenterFactory, or it can be inherited to provide the following:
  • Custom binding rules
  • Custom Ninject Modules

Custom Binding Rules

Custom binding rules allow you to define what Ninject is going to do when an instance of a presenter is requested. You do not need to provide bindings for the IView instances. The IPresenterFactory is responsible for connecting a presenter to the View (which Ninject handles), but if you have other items you wish to inject (such as a Data Service) you can define the binding rule.

Defining custom binding rules

One of the advantages of defining custom binding rules is that it allows you to easily work with the presenters which are available within the core of the Contrib project, and injecting the required data service instances. The following example shows how you can do so.

Creating an instance of a data service
The first thing is that you need to define an instance of your data service:
public class AuthenticationService : IAuthenticationService {
  public bool LogIn(string username, string password) { ... }

  public bool LogOut() { ... }

Creating custom binding rules
Now that we have a class which will represent our Data Service we need to make sure that Ninject is aware of it when we request it. To do this we need to create our own implementation of the WebFormsMvp.Contrib.Ninject.MvpPresenterKernel
public class CustomKernel : MvpPresenterKernel {
  public override void SetupBindings() {

Yes, it's that simple!
Be sure to check out the http://ninject.org/learn for more cool things such as how to do different binding types, creating custom Modules, etc.

Last edited Jan 15, 2010 at 3:31 AM by slace, version 2


No comments yet.