The Bitter Coder Tutorials, Binsor Style: Part XI, Factories
Tue, Sep 9, 2008 2-minute read
Previous posts in the series:factory support facility in Windsor. A “facility” is (as Alex states) an add-in to the Windsor container that changes or adds what the container can do. Facilities are a big part of what makes Windsor so freaking kick-ass, and other facilities are the logging facility, the transaction facility, and (the oft blogged about here) WCF facility.
So, let’s get to the code. Here’s our interface:And our SmsService and SmsConfig classes: Now, showing what is necessary to instantiate our SmsService class: That is not gonna work with Windsor straight away. So, we need a factory to take care of this for us: Right. Now we have to get our supporting Binsor squared away. First off, let's register the facility. Add the following import statement to the top of your .boo file:
import Castle.Facilities.FactorySupport from Castle.MicroKernelSo, Binsor knows where to get the facility. Then, the facility itself:
facility FactorySupportFacilityNow we have to add our factory and our component:
component "smsservice.factory", SmsServiceFactory: userName="joe" password="secret" component "smsservice.default", ISmsService,SmsService: @factoryIdfirstname.lastname@example.org @factoryCreate="CreateService"Last, but not least, the program: Running the console, gives us: SMS Message: testing testing...1.2.3 sent to +465556555 with account joe Seems we're looking at the Decorator Pattern with Windsor next...