The Bitter Coder Tutorials, Binsor Style: XIV Startable Facilities
Previous posts in the series:
facility “startable.facility”, StartableFacilitySo, we register the facilities discussed earlier. BTW, in order to resolve the facilities, I had to add the following to the top of Windsor.boo, in the import section:
facility “logging.facility”,LoggingFacility: loggingApi=LoggerImplementation.Console
component “lame.http”, LameHttpServer: prefix=“http://*:8089/” path=“lame.html”
import Castle.Facilities.Startable from Castle.MicroKernel import Castle.Facilities.LoggingAlso, I added a reference to the Castle.Facilites.Logging assembly. I already had a reference for Castle.MicroKernel from a previous post.
Let’s look at our console code to crank up the server:So, as can be seen above, we
- Create the container, which kicks off the server, coz it’s all Startable and stuff.
- Call GetPage().
- Dispose of the conatainer.
- Call GetPage() again.
- Wonder aloud of Alex minds plagiarism.
[Debug] ‘BitterCoder.Tutorials.Binsor.Core.LameHttpServer’ Starting LameWebService… [Info] ‘BitterCoder.Tutorials.Binsor.Core.LameHttpServer’ LameWebService started…The error at the end of the results is due to us disposing of the container, which decommisions all the components in the container. Alex explains this well…so read what he said.
Client: requesting http://localhost:8089/... Client: success, content follows.
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <html> <head> <title></title> </head> <body> <h1>Lame.html</h1> <h2>Welcome to lame.html file</h2> <p>This is the contents of the lame.html file, neat huh?</p> </body> </html> [Debug] ‘BitterCoder.Tutorials.Binsor.Core.LameHttpServer’ Stopping LameWebService… [Info] ‘BitterCoder.Tutorials.Binsor.Core.LameHttpServer’ LameWebService stopped.
Client: requesting http://localhost:8089/... Client: Exception occurred, message Unable to connect to the remote server
So, I am gonna modify Alex’s final example where he demonstrates lifestyles and their effect on Startable facilities. The only difference, really, is I am going to show you what the Binsor looks like to control the lifestyle of a component.
Here’s our StartableExperiment:And the Binsor:
component “startable.exp”, StartableExperiment: @lifestyle=LifestyleType.Transient(You need to import Castle.Core to get the LifestyleType enum)
Running the following program code:yields:
Started #1 Started #2 Stopped #2 Started #3 Stopped #3 Stopped #1
If I change the @lifestyle attribute in the Binsor to LifestyleType.Singleton, I get:
Started #1 Stopped #1
And that’s Startable Facilities and their lifestyles, from a Binsor point-of-view.
So, I hope someone enjoyed the series. Thanks again to Alex for his tutorials. They were a big rung in my learning ladder for Windsor.
I created a VS.NET project with all the code from this series. If you’re interested, hit me at glenn(dot)goodrich(at)gmail.com.