views:

90

answers:

1

Here's my scenario: I have a ISampleProvider interface:

public interface ISampleProvider<TEntity>
{
TEntity Entity{get;}
}

and here's an implementation for this interface:

public class SampleProvider<TEntity>:ISampleProvider<TEntity>
{
public SampleProvider(TEntity entity)
{
Entity=entity;
}
public TEntity Entity
{
get;private set;
}
}

I'd like to inject an entity into SampleProvider when I resolve it from WindsorContainer So I wrote this:

var container=new WindsorContainer();
container.AddComponent("smaple_provider",typeof(ISampleProvider<Person>),typeof(SampleProvider<Person>));
var arguments=new Hashtable{{"entity",new Person()}};
var sampleProvider=container.Resolve<ISampleProvider<Person>>(arguments);

But it's not working and a dependency resolver exception is thrown that says "Cycle detected in configuration "

Obviously I'm doing something wrong.

+2  A: 

Make sure you have Windsor 2.0 ... This test works fine for me:

[TestFixture]
public class SampleProviderTests {
    public interface ISampleProvider<TEntity> {
        TEntity Entity { get; }
    }

    public class SampleProvider<TEntity> : ISampleProvider<TEntity> {
        public SampleProvider(TEntity entity) {
            Entity = entity;
        }

        public TEntity Entity { get; private set; }
    }

    public class Person {}

    [Test]
    public void test() {
        var container = new WindsorContainer();
        container.AddComponent("smaple_provider", typeof(ISampleProvider<Person>), typeof(SampleProvider<Person>));
        var arguments = new Hashtable { { "entity", new Person() } };
        var sampleProvider = container.Resolve<ISampleProvider<Person>>(arguments);            
    }
}
Mauricio Scheffer