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 7441419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:00:36+00:00 2026-05-29T11:00:36+00:00

I didn’t found short form for this question as subject… Is it possible to

  • 0

I didn’t found short form for this question as subject…

Is it possible to inject already resolved instance’s property to dependency instance’s constructor?

My question arises from MVC tutorial, created in 2009.
It seems like it’s a cyclic dependency to me.

Anyway, can I:

  • grab resolved ContactController (or its base Controller, Listing 3.) instance’s property ModelState
  • and inject it to its dependency ContactService (Listing 4.) instances dependency ModelStateWrapper (Listing 7.)
  • as constructor argument.

_service = new ContactManagerService(new ModelStateWrapper(this.ModelState)); (After Listing 8.)

How to accomplish above line with DI container?

I know that this validation that is happening in Service Layer can be done with data annotations or custom attributes, my question is not so much about design or architecture but possibility.

I have read Ninject wiki, some blog posts, answers, even found somewhat similar situations out there, but not exactly like this or was not able to figure out how to accomplish this or is it possible at all with Ninject.

BR,

  • 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-29T11:00:37+00:00Added an answer on May 29, 2026 at 11:00 am

    No you can’t

    To see the problem you must think about the order in which the objects are created

    var modelStateWrapper = new ModelStateWrapper();
    var service = new ContactService(modelStateWrapper);
    var controller = new ContactController(service);
    

    This means the modelstate wrapper is created longtime before the controller and therefore it is impossible to pass the model state to the ModelStateWrapper’s constructor. The only thing that is doable is to use Property Injection somewhere but this is only a workaround for the actual problem which is that you have a cyclic dependency.

    The implementation also ties the service tightly to the controller. Consider using ModelValidators instead.

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

Sidebar

Related Questions

I have an small question I didn't found an answer yet: how do I
I've found a similar question on stack overflow, but it didn't really answer the
I tried to find a solution but I didn't found what I was searching
I have searched a bit on google, but didn't really found an answer to
I didn't get the answer to this anywhere. What is the runtime complexity of
I didn't see any similar questions asked on this topic, and I had to
I've read most of the relevant answers on this topic already, but I can't
While browsing System.Zip (Delphi XE2) to see how it works, I found this function:
Disclaimer When I wrote this question I was wrong about the behavior of the
Short version of my question: How do I integrate a pair of Google Maps

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.