Created
March 16, 2016 09:59
-
-
Save jberezanski/90e0876bd776224ca277 to your computer and use it in GitHub Desktop.
Windsor TypedFactory conventions
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 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