Skip to content

Instantly share code, notes, and snippets.

@Immerseit
Created September 9, 2013 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Immerseit/6500557 to your computer and use it in GitHub Desktop.
Save Immerseit/6500557 to your computer and use it in GitHub Desktop.
A simple Autofac implementation
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