Skip to content

Add an option for UseNServiceBus to accept Action<EndpointConfiguration> #603

@awright18

Description

@awright18

Describe the suggested improvement

Is your improvement related to a problem? Please describe.

Many .NET configuration APIs accept an Action so that the configuration options don't need to be explicitly created. I'd suggest in this case doing the same

Describe the suggested solution

Change the method to allow for lambda configuration so it's not outside of the scope of the use call.

Also adding the extension to IServiceCollection will IConfiguration options to be easily used instead of other hackery caused by the v2 implementation of this package.

public static IServiceCollection UseNServiceBus(
this IServiceCollection services, 
string endpointName, 
Action<EndpointConfiguration> configuration)
{
   Argument.ThrowIfNull(endpointName);

   Argument.ThrowIfNull(configuration);
   
   var endpointConfiguration = new EndpointConfiguration(endpointName);

   configuration.Invoke(configuration);

   //do whatever the current method does with the endpointConfiguraiton

   // this allows for services method chaining
   return services;
   
}

Describe alternatives you've considered

AddNserviceBus instead of UseNServiceBus. Add is the typical nomenclature for "adding services" via dependency injection. "Use" is typically used in the middleware portion of the pipeline after the App is built. That would be a larger change to consider though.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImprovementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions