Created
September 9, 2013 19:48
-
-
Save Immerseit/6500557 to your computer and use it in GitHub Desktop.
A simple Autofac implementation
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.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using Autofac; | |
namespace Throwit.Business.SomeObjects | |
{ | |
public interface IAnimal | |
{ | |
string RenderAsHtml(); | |
string RegistryName(); | |
} | |
public class Cat : IAnimal | |
{ | |
public string Param { get; set; } | |
public Cat(string param) | |
{ | |
Param = param; | |
} | |
public string RenderAsHtml() | |
{ | |
return Param; | |
} | |
public string RegistryName() | |
{ | |
return System.Reflection.Assembly.GetExecutingAssembly().CodeBase; | |
} | |
} | |
public class CatProgram | |
{ | |
private static IContainer Container { get; set; } | |
public CatProgram() | |
{ | |
ContainerBuilder builder = new ContainerBuilder(); | |
builder.Register((c, p) => new Cat(p.Named<string>("param"))); | |
Container = builder.Build(); | |
var writer = Container.Resolve<Cat>(new NamedParameter("param", "Fizzy, the cat")); | |
writer.RenderAsHtml(); | |
writer.RegistryName(); | |
} | |
private void _test() | |
{ | |
IAnimal c = new Cat("Fizzy"); | |
c.RegistryName(); | |
c.RenderAsHtml(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment