4

I have a generic interface:

public interface IValidationResult<T> where T : struct {
        T Status { set; get; }
        User User { set; get; }
}

And a class that implements the generic interface:

public class ValidationResult : IValidationResult<ValidationResult.ValidationStatus> {
    public enum ValidationStatus { UserNotFound, InvalidPassword, Valid, UserBlankOrSpace }
    public ValidationStatus Status { set; get; }
    public User User { set; get; }

    public ValidationResult (User user, ValidationStatus status) {
        if (user == null) {
            throw new ArgumentNullException ("The User is Null");
        }
        Status = status;
        User = user;
    }
}

I wanna register my interface so I can use DI(Dependency Injection), if both my class and the interface were generic I'd register them as:

services.AddScoped(typeof(IGenericRepository<>), typeof(EFGenericRepository<>));

But it's possible to register a generic interface with a non generic implementation in ASP.NET Core using the built in Dependency Injection? Thanks

1 Answer 1

6

how about

services.AddScoped<IValidationResult<ValidationResult.ValidationStatus>,
                   ValidationResult>();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.