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.dll
from the unofficial NHibernate AddIns project at https://bitbucket.org/fabiomaulo/unhaddins - Download
Ninject.dll
andCommonServiceLocator.NinjectAdapter.dll
from the Ninject project at http://ninject.org - Download
Microsoft.Practices.ServiceLocation.dll
from the Microsoft patterns and practices team and available at http://commonservicelocator.codeplex.com/ - Put these three assemblies in your solution's
Lib
folder
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
IPasswordHasher
with the following method definition:string...