Manipulating configuration from within a feature?


#1

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?


(Charles Solar) #2

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

See


(Ramon Smits) #3

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.


#4

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


(Brandon Ording) #5

INeedInitialization is not new to NSB 7: https://docs.particular.net/nservicebus/lifecycle/ineedinitialization

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