Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:10+00:00 2026-06-01T12:24:10+00:00

I am using FluentValidation and Ninject. I am trying to inject a service into

  • 0

I am using FluentValidation and Ninject. I am trying to inject a service into AbstractValidator

[Validator(typeof(CompetitionFormModelValidator))]
public class CompetitionFormModel
{

    public string FirstName { get; set; }     

}

and for my validation:

public class CompetitionFormModelValidator : AbstractValidator<CompetitionFormModel>
{

    IUserService UserService;

    public CompetitionFormModelValidator(IUserService UserService)
    {

        this.UserService= UserService;

        RuleFor(c => c.FirstName).NotEmpty().WithMessage(" ").Length(1, 100);

        Custom(c =>
        {
            //.. try uusing UserService here


            return null;
        });      



    }
}

In my global.asax.cs

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);

        var ninjectValidatorFactory = new NinjectValidatorFactory(new StandardKernel());
        ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(ninjectValidatorFactory));
        DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
        FluentValidationModelValidatorProvider.Configure(x => x.ValidatorFactory = ninjectValidatorFactory);            

    }

In NinjectWebCommon.cs

private static void RegisterServices(IKernel kernel)
    {
        AssemblyScanner.FindValidatorsInAssembly(Assembly.GetExecutingAssembly())
.ForEach(match => kernel.Bind(match.InterfaceType)
    .To(match.ValidatorType));

        kernel.Bind<IUserService>().To<UserService>();

    } 

The project compiles just fine. When I wasn’t trying to use DI, validation was working just fine too. Now that I am trying inject IUserService, validation isn’t called.

Have I set up the configuration of ninject.web.mvc.fluentvalidation properly ? Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:24:11+00:00Added an answer on June 1, 2026 at 12:24 pm

    In your Application_Start, you new up the NinjectValidatorFactory with a new StandardKernel instead of using your existing kernel – so the validators you registered on your existing kernel won’t be found by the NinjectValidatorFactory.

    Moving this block of code to a place where you have access to the existing kernel and passing that in should fix the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
I'm using Fluent Validation with the Ninject.Web.Mvc.FluentValidation library to automatically wire up all of
I am using fluentvalidation and use structuremap to inject validators for actions in asp.net
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into
Following the article http://www.thekip.nl/2011/09/22/using-fluentvalidation-for-both-domain-validation-and-validation-in-mvc-projects/ for me it's not still clear where does the validation
I have a FluentValidation validator that I want to use to validate a booking.
I am setting up an MVC solution and trying to seperate it out into
Using mercurial, I've run into an odd problem where a line from one committer
Using FluentValidation, is it possible to throw an exception on a single rule failure?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.