2

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...
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433

1 Answers1

1

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433