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

The Archive Base Latest Questions

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

thats the way josh smith is doing the add-a-customer-procedure: **CustomerViewModel**.cs: public void Save() {

  • 0

thats the way josh smith is doing the add-a-customer-procedure:

**CustomerViewModel**.cs:
    public void Save()
    {   
       _customerRepository.AddCustomer(_customer);
    }

        **CustomerRepository**.cs:
        public void AddCustomer(Customer customer)
                {
        //...
                        _customers.Add(customer);

                        if (this.CustomerAdded != null)
                            this.CustomerAdded(this, new CustomerAddedEventArgs(customer));

                }

        **AllCustomersViewModel**.cs(acts as Controller):
        void OnCustomerAddedToRepository(object sender, CustomerAddedEventArgs e)
                {
                    var viewModel = new CustomerViewModel(e.NewCustomer, _customerRepository);
                    this.AllCustomers.Add(viewModel);
                }

strong textWouldn`t it be better to do this?:

 **CustomerViewModel**.cs:
public void Save()
{   
   if (this.CustomerAdded != null)
                        this.CustomerAdded(this, new CustomerAddedEventArgs(customer));
}   

    AllCustomersViewModel.cs(acts as Controller):
    void OnCustomer**ADDING**ToRepository(object sender, CustomerAddedEventArgs e)
            {
                _customerRepository.Add(e.NewCustomer);
                var viewModel = new CustomerViewModel(e.NewCustomer);
                this.AllCustomers.Add(viewModel);
            }

This step in the CustomerViewModel.cs could also be in the Controller because the Controller holds 1/all refererence(s) to the Service/Repository of the Customer/Product/Order etc…

if (this.IsNewCustomer)
                _customerRepository.AddCustomer(_customer);

When I have now still a Order/ProductViewModel working for the same controller I have 3 instances of the repository. If the repository would be in the controller`s Ctor instantiated I have only ONE instance.

With josh smith architecture you have a customerRepo in the Controller AND CustomerViewModel.

With my idea you have only ONE customerRepo in the controller AND the CustomerViewModel`s Save/Add method could be subscribed to the Controllers OnAddCustomer method.

Why did Josh smith took a

public event EventHandler<CustomerAddedEventArgs> CustomerAdded;

and not a

simple public Action<Customer> AddDocumentDelegate;

What do you think? Do you see any disadvantage in my idea?

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

    Your idea is right. The viewModel should be a view specific representation of your model and it should not call your repositories. Your controller could listen on the events from view (button click, submit etc) and then call the repositories.

    There are other posts on this topic you should check –

    http://www.weask.us/entry/mvvm-put-data-access-layer

    MVVM where to put Data Access Layer?

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

Sidebar

Related Questions

I thought what I was doing was right out of the Josh Smith MVVM
I have always admired the way Josh Smith has built his sample application .
is there way thats i can preselect an item when the page loads or
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
I'm writing some WPF code involving Adorners. I'm using Josh Smith's UIElementAdorner.cs (found in
I'm implementing a textbox filter on a list based on Josh Smith's example at
sorry if my question deosnt make sense, but thats the best way i can
Suppose my history goes that way : A - B - C - D
The usual way to resolve lnk involve using WShell.WshShortcut or IShellLink that way :
I need to declare the query variable outside the switch statement that way I

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.