Skip to content

@joshuaflanagan /hello_structuremap.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
using System;
using StructureMap;
namespace ConsoleApplication1
{
class Program {
private static void Main(string[] args) {
IContainer container = ConfigureDependencies();
IAppEngine appEngine = container.GetInstance<IAppEngine>();
appEngine.Run();
}
private static IContainer ConfigureDependencies() {
return new Container(x =>{
x.For<IAppEngine>().Use<AppEngine>();
x.For<IGreeter>().Use<EnglishGreeter>();
x.For<IOutputDisplay>().Use<ConsoleOutputDisplay>();
});
}
}
public class AppEngine : IAppEngine {
private readonly IGreeter greeter;
private readonly IOutputDisplay outputDisplay;
public AppEngine(IGreeter greeter, IOutputDisplay outputDisplay) {
this.greeter = greeter;
this.outputDisplay = outputDisplay;
}
public void Run() {
outputDisplay.Show(greeter.GetGreeting());
}
}
public interface IAppEngine {
void Run();
}
public interface IGreeter {
string GetGreeting();
}
public class EnglishGreeter : IGreeter {
public string GetGreeting() {
return "Hello";
}
}
public class FrenchGreeter : IGreeter {
public string GetGreeting() {
return "Bonjour";
}
}
public interface IOutputDisplay {
void Show(string message);
}
public class ConsoleOutputDisplay : IOutputDisplay {
public void Show(string message) {
Console.WriteLine(message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.