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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:16:24+00:00 2026-06-19T00:16:24+00:00

In an MVC3 application, I need to construct a domain object from values contained

  • 0

In an MVC3 application, I need to construct a domain object from values contained in the incoming Http Request. The logic is sufficiently complex that I have created a factory class with the responsibility of creating my domain object.

My question is whether to pass into this factory class the value of the Controller’s Request property, or should I reference the value of the static HttpContext.Request property from inside the factory class?

My intention is to unit test both the controller and the factory class so I will have perform the necessary overhead of setting up the HttpContext somewhere. I just wondered if there are any general rules to stick to?

  • 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-19T00:16:25+00:00Added an answer on June 19, 2026 at 12:16 am

    Simply pass a NameValueCollection to your factory class:

    public SomeDomainObject ConstructDomainObject(NameValueCollection data)
    {
        ...
    }
    

    and then in your controller simply:

    var domainModel = factory.ConstructDomainObject(Request.Params);
    

    Now you can unit test the ConstructDomainObject method as much as you like.

    If you want to test your controller in isolation then make have this factory object implement an interface:

    public interface IMyFactory
    {
        SomeDomainObject ConstructDomainObject(NameValueCollection data);
    }
    

    that your controller will work with:

    public class SomeController: Controller
    {
        private readonly IMyFactory factory;  
        public SomeController(IMyFactory factory)
        {
            this.factory = factory;
        }
    
        public ActionResult SomeAction()
        {
            var domainModel = this.factory.ConstructDomainObject(Request.Params);
            ...
        }
    }
    

    All this being said, have you considered writing a custom model binder? In ASP.NET MVC the responsibility of the model binder is exactly that: instantiate some model from the request. This way you don’t need to be reinventing some wheels but you will be using what’s natively built into the framework for this purpose.

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

Sidebar

Related Questions

I need to develop a mobile application using mvc3 for capturing images from camera,
On a .net MVC3 application, I need to load the Javascript resource URL from
here's my question: I have an MVC3 C# application and I need to update
i have a problem with my mvc3 application, i need to create some Validation
I'm writing an MVC3 application that will need to make use of URL rewriting
I have a MVC3 application, based on default layout from VS 2010, which I
I have MVC3 web application where we need to populate radio button list with
I'm developing a MVC3 application and need to select the checkboxes label. In ASP
I am working on a mvc3 application and I need to modify the style
I'm a bit new to SSRS... I have an MVC3 application which I need

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.