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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:30:28+00:00 2026-05-31T19:30:28+00:00

First my requirement was We can create an account an put money on it,

  • 0

First my requirement was

“We can create an account an put money on it, when we buy an item we decrease the account”

So my AccountController looked like

class AccountController
{
    private IAccountDataSource _accountDataSource;

    Create(Account anAccount)
    {
        _accountDataSource.Insert(anAccount);
         Render(anAccount.Id);
     }
}

But then there is a new requirement
“Some people can have a free account (all the items will be free), but if we create a real account then we remove the free account”

So my controller.Create became

Create(Account anAccount)
{
    _accountDataSource.Insert(anAccount);
    RemoveFreeAccount(anAccount.Customer);
    Render(anAccount.Id);
}

RemoveFreeAccount(Customer aCustomer)
{
    _accountDataSource.Remove(new AccountFilter() { Type='Free', CustomerId=aCustomer.Id });
}

But for me it feels like I should put this RemoveFreeAccount somewhere else, but I don’t know where because IAccountDataSource is just suppose to handle the data storing.

  • 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-31T19:30:29+00:00Added an answer on May 31, 2026 at 7:30 pm

    The problem shows that you are breaking SRP. Your controller should not contain business logic. Using a repository directly in the controller forces you do put all logic in it and therefore getting two responsibilities (being a bridge between the M in MVC + handling the business logic).

    The first refactoring part should be to move the business logic into the model (in MVC not to be confused with an entity model or a view model)

    this giving your original code the following structure:

    public class AccountService
    {
        void CreateAccount(string accountName)
        {
           var account = new Account(accountName);
            _dataSource.Create(account);
            DomainEvents.Publish(new AccountCreated(account));
        }
    }
    
    public class AccountController
    {
        private AccountService _service;
    
        Create(AccountViewModel model)
        {
            var account = _accountDataSource.Create(model.Name);
            Render(account.Id);
         }
    }
    

    The change might look minor, but is important:

    1. The controller now has only one reason to change (mapping between the view and the model)
    2. Any change of business requirements will not force changes to the UI layer.
    3. Changes in requirements are only made in one place

    To add support for free accounts I would use an event driven model:

    public class FreeAccountService : ISubscriberOf<UserCreated>, ISubscriberOf<AccountCreated>
    {
        public FreeAccountService(AccountService)
        {
        }
    
        public void HandleEvent(UserCreated domainEvent)
        {
            accountService.Create(new FreeAccount());
        }
    
        public void HandleEvent(AccountCreated domainEvent)
        {
            var freeAccount = dbSource.GetFreeAccount();
            if (freeAccount != null)
                accountService.Delete(freeAccount)
        }
    }
    

    Since it requires no changes in the other account service.

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

Sidebar

Related Questions

I have to create a CD inventory program for my first Java class. The
First the requirements: By management requirements, I can't use open source code. I need
First question here so hello everyone. The requirement I'm working on is a small
Requirement : In an app, During the first launch it is required to download
I have a requirement where I have to register users first via email. So,
Thanks for your replies. First I am explaining my requirement :- I created my
First off, I know I can copy "this" on instantiation, but that doesn't work
I have a seemingly simple requirement, but i can't figure out how to write
I can't be the first person to have this problem, I must be missing
Hi Experts, I have a requirement in which I have to create a hover

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.