Using dependency injection with entities
In this recipe, we will show you how you can inject services into your entities to separate implementation details from your real business logic.
Getting ready
- Download
uNHAddIns.CommonServiceLocatorAdapters.dllfrom the unofficial NHibernate AddIns project at https://bitbucket.org/fabiomaulo/unhaddins - Download
Ninject.dllandCommonServiceLocator.NinjectAdapter.dllfrom the Ninject project at http://ninject.org - Download
Microsoft.Practices.ServiceLocation.dllfrom the Microsoft patterns and practices team and available at http://commonservicelocator.codeplex.com/ - Put these three assemblies in your solution's
Libfolder
How to do it…
- Create a new console application project named
IoCByteCode. - Add a reference to
NHibernate.dll,Ninject.dll,CommonServiceLocator.NinjectAdapter.dll,uNHAddIns.CommonServiceLocatorAdapters.dll, andMicrosoft.Practices.ServiceLocation.dll. - Add an interface named
IPasswordHasherwith the following method definition:string...