Creating simpler fluent interface I have the following:

public interface IBehaviour
{
    event EventHandler Completed;
    void Execute();
}

public interface IBehaviourA : IBehaviour
{
    // Some specific stuff here
    object A { get; set; }
}

public interface IBehaviourB : IBehaviour
{
    // Some specific stuff here
    object B {get;set;}
}

public interface IBehaviourQueue
{
    void Run();
    BehaviourQueueItem&lt;IBehaviour&gt; AddBehaviour&lt;T&gt;() where T : IBehaviour;
}

public class BehaviourQueue : Queue&lt;BehaviourQueueItem&lt;IBehaviour&gt;&gt;,  IBehaviourQueue
{
    private IBehaviourFactory factory;
    public BehaviourQueue(IBehaviourFactory factory)
    {
        this.factory = factory;
    }

    public BehaviourQueueItem&lt;IBehaviour&gt; AddBehaviour&lt;T&gt;() where T:IBehaviour
    {
        T behaviour = factory.GetNew&lt;T&gt;();
        var queueItem = new BehaviourQueueItem&lt;IBehaviour&gt;(behaviour);
        Enqueue(queueItem); 
        return queueItem;
    }

    public void Run()
    {
        //Run each queue item
    }
}

public class BehaviourQueueItem&lt;T&gt;
{
    public IBehaviour behaviour;

    public BehaviourQueueItem(IBehaviour behaviour)
    {
        this.behaviour = behaviour;
    }

    public void WhenComplete(Func&lt;T, bool&gt; action) 
    {
        CompletedAction = action;
    }

    public BehaviourQueueItem&lt;T&gt; ConfigureFor&lt;Z&gt;(Action&lt;Z&gt; dow) where Z : IBehaviour
    {
        dow((Z)behaviour);
        return this;
    }
}


This is how it is used:

var q =new BehaviourQueue(new BehaviourFactory()); // Queue here is IBehaviour
q.AddBehaviour&lt;IBehaviourA&gt;()
 .ConfigureFor&lt;IBehaviourA&gt;(x =&gt; x.A = "someValueA")
 .WhenComplete(x =&gt; DoStuffWithSomeProperty(((IBehaviourA)x).A));

q.AddBehaviour&lt;IBehaviourB &gt;()
 .ConfigureFor&lt;IBehaviourB &gt;(x =&gt; x.B = "someValueB")
 .WhenComplete(x =&gt; DoStuffWithSomeProperty(((IBehaviourB)x).B));


What I don't really like is that I have to specify which type of IBehaviour I am referring to every time. I would like to be able to write:

var q =new BehaviourQueue(new BehaviourFactory()); // Queue here is IBehaviour
q.AddBehaviour&lt;IBehaviourA&gt;()
 .Configure(x =&gt; x.A = "someValueA")
 .WhenComplete(x =&gt; DoStuffWithSomeProperty(x.A));

q.AddBehaviour&lt;IBehaviourB&gt;()
 .Configure(x =&gt; x.B = "someValueB")
 .WhenComplete(x =&gt; DoStuffWithSomeProperty(x.B));


I know that I have to modify this part:

public BehaviourQueueItem&lt;IBehaviour&gt; AddBehaviour&lt;T&gt;() where T:IBehaviour
{
    T behaviour = factory.GetNew&lt;T&gt;();
    var queueItem = new BehaviourQueueItem&lt;IBehaviour&gt;(behaviour);
    Enqueue(queueItem);
    return queueItem;
}


to something like

public BehaviourQueueItem&lt;T&gt; AddBehaviour&lt;T&gt;() where T:IBehaviour
{
    T behaviour = factory.GetNew&lt;T&gt;();
    var queueItem = new BehaviourQueueItem&lt;T&gt;(behaviour);
    Enqueue(queueItem); // It won't let me know do it because of Covariance/Contravariance thingy
    return queueItem;
}


Do you have any idea what I should write to be able to create a base typed list and add specific items and configuring it fluently?

Keep in mind that I should be able to add any type of IBehaviour to BehaviourQueue so the queue can't be a derived type.
If I understand it right, you would want IBehaviourA associated with property A, and IBehaviourB with property B.

If the above is right, could you try something like:

BehaviourQueueItem&lt;T&gt; AddBehaviour() where T : IBehaviour;


instead of 

BehaviourQueueItem&lt;IBehaviour&gt; AddBehaviour&lt;T&gt;() where T : IBehaviour;


By this we can determine the object type at BehaviourQueueItem class level itself.