Question

I want to set a value to a public boolean property in my NServicebus message handler through EndPoint config.

One way which I know is by creating

  1. An interface with that boolean property.
  2. A concrete class inherited from the interface.
  3. Initializing / Setting the value in that concrete class.
  4. Injecting the concrete class through End-point config.

Is there any other way to achieve this.

Était-ce utile?

La solution

Configure.Instance.Configurer
  .ConfigureProperty<YourHandlerType>(h => h.BoolProperty,
      Bool.Parse(ConfigurationManager.AppSettings["YourSetting"]));

In future versions, this will be even easier.

Edit:
You can try registering late with IWantToRunBeforeConfigurationIsFinalized, as suggested by David.

You can also register the component early. Since NServiceBus registers handlers as DependencyLifecycle.InstancePerUnitOfWork, your code should be doing the same

Configure.Component<YourHandlerType>(DependencyLifecycle.InstancePerUnitOfWork)
  .ConfigureProperty(h => h.BoolProperty,
      Bool.Parse(ConfigurationManager.AppSettings["YourSetting"]));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top