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

  • Home
  • SEARCH
  • 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 4081952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:07:36+00:00 2026-05-20T18:07:36+00:00

I have a controller with a constructor like so: Public Sub New(Service As ICategoryService)

  • 0

I have a controller with a constructor like so:

Public Sub New(Service As ICategoryService)

The service’s constructor looks like this:

Public Sub New(Repository As IRepository(Of Category), IValidationDictionary)

I have a class Named ModelStateWrapper that implements IValidationDictionary:

Public Class ModelStateWrapper
    Implements IValidationDictionary

    Private ModelState As ModelStateDictionary

    Public Sub New(ModelState As ModelStateDictionary)
        Me.ModelState = ModelState

    End Sub

    Public Sub AddError(Key As String, Message As String) Implements Core.Interfaces.IValidationDictionary.AddError
        ModelState.AddModelError(Key, Message)

    End Sub

    Public ReadOnly Property IsValid As Boolean Implements Core.Interfaces.IValidationDictionary.IsValid
        Get
            Return ModelState.IsValid
        End Get
    End Property

End Class

I want to inject the ModelState of the controller into the ModelStateWrapper, and inject that into the service. Is this possible?

I have looked at custom providers in Ninject, and have the controllers inherit a BaseController class, but it does not seem to work. Any ideas?

Also, what is the standard way to do validation in the service layer that can be used from the controller?

  • 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-05-20T18:07:37+00:00Added an answer on May 20, 2026 at 6:07 pm

    It seems like you would have a problem trying inject ModelState because of the fact that once in an action method you already have the instance of ModelState that you want to pass into your wrapper.

    Not every single object needs to or should be injected. Sometimes, this case potentially being one of those times, it is cleaner and easier and simpler to “inject” or provide the dependency or object as a parameter to the method that requires it. That is, pass IValidationDictionary as a parameter to the methods in your Service. Construct a ModelStateWrapper in the controller (new it up or use a Factory), and pass it in.

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

Sidebar

Related Questions

Lets say I have a controller class like this. public class InStorePickupController : Controller
I have a model that looks something like this: public class SampleModel { public
My application I have an application design that looks like this: web application layer
I have a controller called NewsController, the constructor of this controller receives an INewsService
I have controller with action new , and I want it to create ActiveRecord::Base
I have a controller with an action method as follows: public class InventoryController :
I have a controller action which I would like to call another controller action.
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
I have a controller defined as: [AcceptVerbs(HttpVerbs.Post)] public JsonResult PostMoreData(DataContracts.Address address, DataContracts.GeoLocation geoLocation) {
I've set up DI with Ninject in my ASP.NET MVC application like this Bind<IRepository>().To<XmlDefaultRepository>().WhenInjectedInto(typeof(PageController)).WithConstructorArgument(contentType,

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.