Service mapping

Nov 6, 2010 at 5:03 PM

Hi,

how do i map an interface to a specified (manually created) class instance with nRoute?

thanks!

Coordinator
Nov 8, 2010 at 6:02 PM

It's quite simple, say you have an interface called ICalenderService, then you could do something like:

 

[MapService(typeof(ICalenderService), InitializationMode = InitializationMode.OnDemand, Lifetime = InstanceLifetime.Singleton)]
public class CalenderService : ICalenderService
{
     // implementation goes here
}

 

now, in case you don't own CalenderService then you could do something like:

[assembly:DefineService(typeof(ICalenderService), typeof(CalenderService), 
 InitializationMode = InitializationMode.OnDemand, Lifetime = InstanceLifetime.Singleton)]

So in the case above you are defining a service, and in the earlier case you were mapping a type as being a service implementation.

Hope this helps,
Rishi