Say is a simple application, do not explain some special operations, specific series of articles can look at Terrylee's Castle.net series of articles. But the version is a bit old.
I downloaded the castle.windsor.2.5.3. can go to the official website to download.
This example makes a simple example of sending a message. To learn castle.
First set up two interfaces, a send message interface isend, an information content format interface imessage, here can image of the interface as a service to see.
Namespace Castlenetdem2.container
{
Interface Isend
{
void Send (string Message);
}
}
Namespace Castlenetdem2.container
{
Interface IMessage
{
String Formmessage (string message);
}
}
It then builds the components that implement the two services, the implementation class.
Namespace Castlenetdem2.components
{
Class Messagepro:imessage
{
String Formmessage (string message)
{
"]";
}
}
}
Namespace Castlenetdem2.components
{
Class Sendpro:isend
{
Public Sendpro () {}
Private IMessage _msgobj;
{
This._msgobj = msg;
}
void Send (string Message)
{
Console.WriteLine ("{0} sent to {1} message: {2}", Sendform, SendTo, _msgobj.formmessage (message));
}
}
}
The next most important thing is to write the configuration file,
<configsections>
<nametype= "Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, castle.windsor"/ >
</configsections>
<Castle>
<components>
<IDService= "CastleNetDem2.Container.ISend, CastleNetDem2"
Type= "CastleNetDem2.Components.SendPro, CastleNetDem2">
<parameters>
<msg>${message}</msg>
</Parameters>
</Component>
<IDService= "CastleNetDem2.Container.IMessage, CastleNetDem2"
Type= "CastleNetDem2.Components.MessagePro, CastleNetDem2"/>
</Components>
</Castle>
It is important to note that the construction injection of Sendpro needs to pass in a Message object. Introduced with ${}.
Test:
void Main (string[] args)
{
Container
New WindsorContainer (new Xmlinterpreter ());
Isend send = container. Getservice<isend> ();
Send. Send ("I'm home.");
Console.readkey ();
}
Operation Result: