Home > Development > Castle Manual Registration

Castle Manual Registration

to register types against interfaces in castle manually you can do the following:


This is the new way to register types they old way is to use the AddCompanent method on the container. The above code registers the EmailService class against its interface IEmailService gives it a name so you ask the container for a type via a key and sets the lifecycle to transient so you get a new object everytime you ask the container for an object of type IEmailService.

You ask for an instance of IEmailService using the following:

IEmailService es = container.Resolve<IEmailService>();

This is pretty basic usage of the container but is enought to get going. There are heaps more options like ServiceOverrides which we will look at later.

Categories: Development Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: