0

I have the following repository which is a generic with two-parameter

   public interface IClownRepository
    {
    }

    public interface IClownRepository< TEntity> : IClownRepository<TEntity, int>, IClownRepository
        where TEntity : Entity<int>
    {

    }

    public interface IClownRepository<TEntity, in TIdentifier> : IClownRepository 
        where TEntity : Entity<TIdentifier>
        
    {
        IQueryable<TEntity> All();

        Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);

        Task<TEntity> SaveOrUpdateAsync(TEntity entity);

        Task DeleteAsync(TEntity entity);

        void Delete(TIdentifier id);

        Task DeleteAsync(TIdentifier id);

        void Delete(Expression<Func<TEntity, bool>> predicate);

        Task DeleteAsync(Expression<Func<TEntity, bool>> predicate);

        Task UpdateAsync(TEntity entity);

        Task SaveAsync(TEntity entity);
    }

And here's the registration on Simple Injector

   services.AddTransient(typeof(IClownRepository<>), typeof(ClownRepository<,>));

When I run the application I've got the following exception

ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition.

Now I know it's due to the ClownRepository<TDBContext, T> but I don't really know how to define it in the service's registration... Any suggestion?

Thanks in advance

EDIT ClownRepository :

 public class ClownRepository<TDBContext, T> : IClownRepository<T>
        where T : Entity<int>
    where TDBContext : ClownDbContext
    {
        private readonly TDBContext dbContext;
        public virtual DbSet<T> Set => this.dbContext.Set<T>();

        public ClownRepository(TDBContext context)
        {
            this.dbContext = context;
        }
        public IQueryable<T> All()
        {
            throw new NotImplementedException();
        }

        public void Delete(int id)
        {
            var item = this.Set.FirstOrDefault(x => x.Id == id);

            if (item != null)
            {
                if (item is ISoftDelete)
                {

                }
            }
        }

        public void Delete(Expression<Func<T, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public Task DeleteAsync(T entity)
        {
            throw new NotImplementedException();
        }

        public Task DeleteAsync(int id)
        {
            throw new NotImplementedException();
        }

        public Task DeleteAsync(Expression<Func<T, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public Task<T> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate)
        {
            return Set.FirstOrDefaultAsync(predicate);
        }

        public Task SaveAsync(T entity)
        {
            throw new NotImplementedException();
        }

        public Task<T> SaveOrUpdateAsync(T entity)
        {
            throw new NotImplementedException();
        }

        public Task UpdateAsync(T entity)
        {
            throw new NotImplementedException();
        }
    }

StackTrace :

   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngine engine, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateServiceProvider(Object containerBuilder)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at ClownOnCore.Web.Program.Main(String[] args) in C:\Projects\ClownOnCore\ClownOnCore.Web\Program.cs:line 27
3
  • Please post the definition of ClownRepository<,>.
    – Steven
    Sep 14, 2021 at 16:03
  • This is NOT a Simple Injector registration: services.AddTransient(typeof(IClownRepository<>). This is likely MS.DI and MS.DI is very limited in its generic capabilities. You need to post more details on what you are doing.
    – Steven
    Sep 14, 2021 at 16:05
  • And please post the full stack trace.
    – Steven
    Sep 14, 2021 at 16:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.