I am building out a basic ninject container to replace phone container in Caliburn.Micro as I want to stick with one IoC container for multiple projects. Plus its fun...
One of the methods is register with phone services which looks like this:
public void RegisterPhoneServices(bool treatViewAsLoaded = false)
{
var _phoneService = new PhoneApplicationServiceAdapter(_rootFrame);
var _navigationService = new FrameAdapter(_rootFrame, treatViewAsLoaded);
_kernel.Bind<INavigationService>().ToMethod(x => _navigationService);
_kernel.Bind<IPhoneService>().ToMethod(x => _phoneService);
_kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
_kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
_kernel.Bind<TaskController>().ToSelf().InSingletonScope();
var _taskController = Kernel.Get<TaskController>();
_taskController.Start();
}
The part I do not understand is why the INavigationService and the IPhoneService are binded to anonymous methods like they are, rather than a standard binding.
I THINK the reason is because this is the correct way to bind to an object that you already have defined an instance for (as is the case in the lines above) but I hate seeing code and not knowing what it does. Am I correct in my assumption?
deanvmc,
in short: yes, you're right.
you're using a Ninject factory method (see http://bit.ly/AB9Eg9). The factory could return any kind of INavigationService
in your case you're simply choosing to return your existing PhoneApplicationServiceAdapter
Cheers!