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

The Archive Base Latest Questions

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

Last week, I downloaded source code of a blog engine developped in ASP.NET MVC3.

  • 0

Last week, I downloaded source code of a blog engine developped in ASP.NET MVC3. When analyzing the code, I noticed they used a different way for retrieving data for filling the view model.

Here is an example for the ‘post’ view model:

The controller:

public ActionResult Details(string slug)
{
    var model = new PostDetailsViewModel(UnitOfWork, slug);         
    return View(model);
}

The view model:

public PostDetailsViewModel(IUnitOfWork unitOfWork, string slug)
    {
        _repository = new PostRepository(unitOfWork);
        Post = _repository.FindBySlug(slug);
    }

The repository:

    public Post FindBySlug(string slug)
    {
        return FindAll().SingleOrDefault(x => x.Slug == slug);
    }

As you can see, the repository is instantiated directly in the view model (in the constructor). Is it a right way?

Usually, I used a business layer and eventually a service layer like this:
Controller >> Business >> Repository

Thanks for your advice.

  • 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-27T18:22:08+00:00Added an answer on May 27, 2026 at 6:22 pm

    Is it a right way?

    Doesn’t seem to me like a right way. Normally you could do this repository access in the model, not in the view model. Also they seem to have a property called Post in the view model. So they are referencing the domain model in the view model which I wouldn’t do.

    As far as hardcoding a specific implementation of a repository in the constructor is concerned, well, if you don’t care about things like weak coupling between the layers, reusability, maintenance, unit testing, … you could do it. Nobody can convince us that IoC should always be done. It has its pros and cons.

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

Sidebar

Related Questions

Until last week, I developed with SQL Server 2008 non-R2 and my ASP.NET MVC
I used python to write an assignment last week, here is a code snippet
Last week , my boss ask my team to evaluate ASP.NET MVC, for next
since last week I've been busy with mvc3. I'm new to the whole .net
Last week at Mix '09, the final version of ASP.NET MVC 1.0 was released.
Last week we released Omniture's analytics code onto a large volume of web sites
I've spent the last week developing code to connect to a Web Service using
I was writing some Unit tests last week for a piece of code that
Last week I was a debugging a code and a weird situation came up:
During last week I received some code and was asked to improve the performance.

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.