Skip to content

Instantly share code, notes, and snippets.

@jberezanski
Created March 16, 2016 09:59
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 jberezanski/90e0876bd776224ca277 to your computer and use it in GitHub Desktop.
Save jberezanski/90e0876bd776224ca277 to your computer and use it in GitHub Desktop.
Windsor TypedFactory conventions
using System;
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
namespace WindsorFactories
{
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();
container.Register(
Component.For<IBla>().ImplementedBy<CompA>().Named("A"),
Component.For<IBla>().ImplementedBy<CompB>().Named("B"),
Component.For<IBlaFactory>().AsFactory());
var f = container.Resolve<IBlaFactory>();
IBla x;
x = f.GetA();
x.Frob();
x = f.GetB();
x.Frob();
x = f.CreateX();
x.Frob();
}
}
public interface IBla
{
void Frob();
}
abstract class Comp : IBla
{
public void Frob()
{
Console.WriteLine(this.GetType().FullName);
}
}
class CompA : Comp
{
}
class CompB : Comp
{
}
public interface IBlaFactory
{
IBla GetA();
IBla GetB();
IBla CreateX();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment