在使用类型化的工厂设施时,我希望以下内容生成两个单独的实例.
using System;
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();
container.Register(Component
.For<IFactory>()
.AsFactory()
.LifestyleSingleton());
container.Register(Component
.For<IImplementation>()
.ImplementedBy<Implementation>()
.LifestylePerThread());
var factory = container.Resolve<IFactory>();
var implementation1 = factory.Create(1);
var implementation2 = factory.Create(2);
Console.WriteLine(implementation1 == implementation2);//Returns true!
Console.Read();
}
}
public interface IFactory
{
IImplementation Create(int dependency);
}
public interface IImplementation
{}
public class Implementation : IImplementation
{
private readonly int _dependency;
public Implementation(int dependency) …Run Code Online (Sandbox Code Playgroud)