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

The Archive Base Latest Questions

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

Many open source projects use a Configuration class and lambda’s to clarify configuring a

  • 0

Many open source projects use a Configuration class and lambda’s to clarify configuring a complex object. Take Mass Transit for example. A simple configuration would be like so.

Bus.Initialize(sbc =>
        {
            sbc.UseMsmq();
            sbc.VerifyMsmqConfiguration();
            sbc.VerifyMsDtcConfiguration();
            sbc.UseMulticastSubscriptionClient();
            sbc.ReceiveFrom("msmq://localhost/test");
        });

When you hover over Initialize in Visual Studio it says the parameter for the method call is Action<ServiceBusConfigurator>. I was wondering if anyone could show a simple example of how to use this pattern on a class. I don’t even know what to call this type of pattern and my “GoogleFu” is not working as of yet. In this particular case I realize the method is operating on a singleton pattern. But I am ok with it being an instance method on a class.

  • 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-28T19:54:41+00:00Added an answer on May 28, 2026 at 7:54 pm

    An Action<ServiceBusConfigurator> is a method which accepts a single parameter of type ServiceBusConfigurator, does an “action” operating on that instance, and returns nothing (void).

    .NET BCL (starting from 3.5) comes with predefined generic delegate signatures: Action<T>, Action<T1, T2> (etc.) for methods which don’t return a value, and Func<Tresult>, Func<T, Tresult> (etc.) for methods accepting zero of more parameters and returning a single result instance of type Tresult.

    When you create a method which accepts a delegate, you allow callers of your method to pass more than just data parameters – your method actually delegates a part of responsibility to external code. In your case, Bus.Initialize creates an instance of ServiceBusConfigurator (sbc), and then calls the specified action with the sbc instance as the parameter.

    This basically lets your method control the lifetime of the configuration class instance. It is up to the caller to fill in the details, but actual instance is provided by your class:

     // this is not actual mass transit source code
     public class BusCreator
     {
         public static IBus Initialize(Action<IConfiguration> action)
         {
             // create the config instance here
             IConfiguration config = CreateDefaultConfig();
    
             // let callers modify it
             action(config);
    
             // use the final version to build the result
             return config.Build()
         }
     }
    

    The benefit is that your built instance (the imaginary IBus in this case) cannot be modified further. Configuration instance is only created shortly, passed to an external method, and then used to create an immutable final object:

     IBus result = BusCreator.Configure(cfg => cfg.BusType = BusType.MSMQ);
    

    Two things to note in the line above:

    1. The code inside the anonymous method is wrapped inside a delegate passed to the method. It is not executed until the Configure method actually calls it.

    2. The cfg parameter is created by the Configure method and passed to the lambda. After the method returns, this object doesn’t exist anymore (or is wrapped inside the resulting object).

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

Sidebar

Related Questions

We use multiple open source projects in our project. We have many changes spread
we use ASP.NET with C# and based on open source projects/articles I passed through,
I noticed many mentions of pty and tty in some open source projects, could
In many open source projects, the test suite that is used is often comprehensive.
You can find many open source projects in the INTERNET (such as Linux,open office,...)
Contributing to open source can have many forms: working with issue trackers, patches, further
Many people suggest to develop web applications in open source technologies. And one of
Why aren't many commercial, 3D video games (not random open source 2D ones) written
My question is in regard to referencing open source frameworks. There are many of
I was wondering how valuable open-source projects are to learn from? I still consider

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.