user1019359
user1019359

Reputation: 27

Unity 2.0 IOC Configuration about Generic class

I want some Repository class extend one common generic class to perform some common operation, problem is: how to config a UserExRepository type in config file.

public class UserExRepository : Repository<User>, IUserEx
{
    public UserExRepository(Context context):base(context){ }
}

public abstract class Repository<TObject> : IRepository<TObject>
    where TObject : class
{
    protected Context Context = null;

    public Repository(Context context)
    {
        Context = context;
    }
    // do some common operation about entity, like create, delete...
}

Upvotes: 2

Views: 596

Answers (1)

abatishchev
abatishchev

Reputation: 100348

You can configure binding generic to generic, generic to non-generic, non-generic to generic,

<unity>
    <containers>
        <container>
            <types>
                 <type type="Repository`1[[User]]" mapTo="UserExRepository ">
            </types>
        </container>
    </containers>
</unity>

but you cannot configure generic constraint.

Upvotes: 1

Related Questions