Manipulating configuration from within a feature?

I want to create a feature that is enabled by default and informs NSB what serializatation to use for the endpoint.

endpointConfiguration.UseSerialization<NewtonsoftSerializer>();

I cannot figure out how to do this from the virtual setup method.

Is this possible? or does every endpoint have to make this call?

You’d want to have an extension method off the Configure object - you only get ReadOnlySettings during feature setup

See

A feature can be enabled by default by doing that in the feature its constructor:

public class FeatureEnabledByDefault :
    Feature
{
    public FeatureEnabledByDefault()
    {
        EnableByDefault();
    }

    protected override void Setup(FeatureConfigurationContext context)
    {
    }
}

If all you want to do is setup a default serializer then you can easiliy do that using INeedInitialization.

class NeedsInitialization :
    INeedInitialization
{
    public void Customize(EndpointConfiguration endpointConfiguration)
    {
        endpointConfiguration.UseSerialization<NewtonsoftSerializer>();
    }
}

Or you can do it explicitly like Charles shared, but the above options can help you do this based on assembly scanning.

1 Like

I guess I should have mentioned I was using NSB 6, can’t use INeedInitialization… yet,

INeedInitialization is not new to NSB 7: Custom Endpoint Initialization • NServiceBus • Particular Docs

It’s been around for a long time, as you see with the Switch Version button on the page.