public class SmsService : ISmsService
{
private SmsConfig _config;
public void SetConfig(SmsConfig config)
_config = config;
}
public void SendMessage(string number, string message)
Console.WriteLine("SMS message: {0} sent to: {1} with account: {2}", message, number, _config.UserName);
public class SmsConfig
private string _userName;
private string _password;
private int _retryAttempts;
internal string UserName
get { return _userName; }
internal string Password
get { return _password; }
public int RetryAttempts
get { return _retryAttempts; }
set { _retryAttempts = value; }
public void SetCredentials(string userName, string password)
_userName = userName;
_password = password;
public interface ISmsService
void SendMessage(string number, string message);
SmsService service = new SmsService();
SmsService.SmsConfig config = new SmsService.SmsConfig();
config.SetCredentials("joe", "secret");
config.RetryAttempts = 3;
service.SetConfig(config);
public class SmsServiceFactory
public ISmsService CreateService()
return service;
private int _retryAttempts = 3;
public SmsServiceFactory(string userName, string password)
config.SetCredentials(_userName, _password);
config.RetryAttempts = _retryAttempts;
<configuration>
<configSections>
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
<castle>
<facilities>
<facility
id="factorysupport"
type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel" />
</facilities>
<components>
<component id="smsService.Factory"
type="IoC.Tutorials.Part11.SmsServiceFactory, IoC.Tutorials.Part11">
<parameters>
<userName>joe</userName>
<password>secret</password>
</parameters>
</component>
<component id="smsService.default"
type="IoC.Tutorials.Part11.ISmsService, IoC.Tutorials.Part11"
factoryId="smsService.Factory"
factoryCreate="CreateService" />
</components>
</castle>
</configuration>
static void Main(string[] args)
WindsorContainer container = new WindsorContainer(new XmlInterpreter());
ISmsService smsService = container.Resolve<ISmsService>();
smsService.SendMessage("+465556555", "testing testing...1.2.3");
Console.Read();