문제

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.

도움이 되었습니까?

해결책

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"]));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top