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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:05:24+00:00 2026-06-13T20:05:24+00:00

Most examples of a DCI Context are implemented as a Command pattern. When using

  • 0

Most examples of a DCI Context are implemented as a Command pattern. When using Dependency Injection though, it’s useful to have the dependencies injected in the constructor and send the parameters into the executing method. Compare the Command pattern class:

public class SomeContext
{
    private readonly SomeRole _someRole;
    private readonly IRepository<User> _userRepository;

    // Everything goes into the constructor for a true encapsuled command.
    public SomeContext(SomeRole someRole, IRepository<User> userRepository)
    {
        _someRole = someRole;
        _userRepository = userRepository;
    }

    public void Execute()
    {
        _someRole.DoStuff(_userRepository);
    }
}

With the Dependency injected class:

public class SomeContext
{
    private readonly IRepository<User> _userRepository;

    // Only what can be injected using the DI provider.
    public SomeContext(IRepository<User> userRepository)
    {
        _userRepository = userRepository;
    }

    // Parameters from the executing method
    public void Execute(SomeRole someRole)
    {
        someRole.DoStuff(_userRepository);
    }
}

The last one seems a bit nicer, but I’ve never seen it implemented like this so I’m curious if there are any things to consider.

  • 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-13T20:05:25+00:00Added an answer on June 13, 2026 at 8:05 pm

    There’s a contrast between Command and DCI. In Command you distribute the interaction between objects, in DCI you centralize the interaction through rolemethods. In the MoneyTRansfer example the accounts will not have the ability to withdraw or deposit becasue they are simple data with no behavior. however in a context such as Transfer that behavior will exist for the roles. So when the source account role is bound to an account object the account object gets the withdraw behavior and the same is true for the destination account.

    In the command pattern they have the behavior but the execution of the behavior is scripted in the command object and can be passed around. The entire interaction is not part of the command object but typically distributed between the participating objects.

    In Marvin, a language build to support DCI as a result of the realization that most modern languages only partly supports DCI, you can only bind roles to objects in the constructor. How you call the constructor is of no concern to the context. This ensures that the binding is done once for all roles. Rebinding is then only possible by instantiation of another context. This is not a constraint from DCI but a design choice for Marvin.

    To the question about whether or not an context method can take arguments, it’s a bit philosophical but as far as I remember the last time I debatted it with Trygve Reenskaug we agreed that they could take arguments and I know that I’ve implemented a few examples (the moneytransfer at the DCI site included) where they do.

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

Sidebar

Related Questions

Most examples I have found use Trace.WriteLineIf e.g. `Trace.WriteLineIf(mySwitch.TraceError,my error);' but using Trace.TraceError(my error);
In most examples that you find on the web when explicitly not using using,
Most examples I see about hosting WCF in IIS have you create an Application
Is there a standard on JSON naming? I see most examples using all lower
I have looked at the network documentation for Unity and most examples seem to
I am new to directx, but have been surprised that most examples I have
Most examples I've seen have scripts in a html page being enclosed by <!--
Most examples of bundle identifiers have three parts. Are four part bundle identifiers valid
Most examples show how to redirect all subdomain traffic to a primary domain, maintaining
Most examples of creating remote branches involve pushing from a local branch Is there

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.