Last active
April 28, 2023 19:54
-
-
Save kleinron/7e2f4562b0df2dfb8d3ff2ec82116e04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Configuration; | |
using Microsoft.Practices.Unity; | |
using Microsoft.Practices.Unity.Configuration; | |
namespace Canberra.InterfacesDemo.WebApp | |
{ | |
public class Global : System.Web.HttpApplication | |
{ | |
public static UnityContainer Container; | |
protected void Application_Start(object sender, EventArgs e) | |
{ | |
Container = new UnityContainer(); | |
var section = (UnityConfigurationSection)ConfigurationManager | |
.GetSection("unity"); | |
section.Configure(Container); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Canberra.InterfacesDemo.Lib | |
{ | |
public class CustomersReminder | |
{ | |
public void Remind(ICustomersFetcher customersFetcher, IEmailSender emailSender) | |
{ | |
foreach (var customer in customersFetcher.GetSleepingCustomers()) | |
{ | |
emailSender.SendRemindMessage(customer.FirstName, customer.LastName, customer.EmailAddress); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Canberra.InterfacesDemo.Lib | |
{ | |
public class CustomersReminder | |
{ | |
public void Remind(ICustomersFetcher customersFetcher, IEmailSender emailSender) | |
{ | |
foreach (var customer in customersFetcher.GetSleepingCustomers()) | |
{ | |
emailSender.SendRemindMessage(customer.FirstName, customer.LastName, customer.EmailAddress); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var container = new UnityContainer(); | |
var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); | |
section.Configure(container); | |
var customersReminder = new CustomersReminder(); | |
customersReminder.Remind(new CustomersFetcher(), container.Resolve<IEmailSender>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var customersReminder = new CustomersReminder(); | |
customersReminder.Remind(new CustomersFetcher(), | |
Global.Container.Resolve<IEmailSender>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var customersReminder = new CustomersReminder(); | |
customersReminder.Remind(new CustomersFetcher(), new EmailSender()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration> | |
<configSections> | |
<section | |
name="unity" | |
type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, | |
Microsoft.Practices.Unity.Configuration" | |
/> | |
</configSections> | |
<unity> | |
<typeAliases> | |
<typeAlias | |
alias="IEmailSender" | |
type="Canberra.InterfacesDemo.Lib.IEmailSender, | |
Canberra.InterfacesDemo.Lib" | |
/> | |
<typeAlias | |
alias="EmailSender" | |
type="MyMail.EmailSender, MyMail" | |
/> | |
</typeAliases> | |
<containers> | |
<container> | |
<types> | |
<type type="IEmailSender" mapTo="EmailSender"/> | |
</types> | |
</container> | |
</containers> | |
</unity> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment