Implementing custom service object: reach access to service instance configuration settings?


Badge +3

I'm implementing service objects within a custom assembly.


 


My ServiceBroker (class inheriting ServiceAssemblyBase) is defining some configuration elements, and I can see them in the smart object tester


I do that like that:


public override string GetConfigSection() {
this.Service.ServiceConfiguration.Add("webserviceurl", true, "default url (it will not work)");
}

My service object isn't inheriting from anything and is just tagged with attributes to make it's declaration valid.


Inside my service object instance, how do I gain access to the configuration values that I've defined?


3 replies

Badge +8

You should be able to do something like the following in the Execute method:


base.Service.ServiceConfiguration["webserviceurl"].ToString(); 


 


Here are some blogs that I wrote that may help.  Also check out the K2 book that we wrote...


http://www.k2distillery.com/2007/11/create-custom-blackpearl-smartobject.html


http://www.k2distillery.com/2008/09/creating-custom-smartobjects-part-2.html

Badge +3

Japergis, thanks for the articles, the second one gave me a good bootstrap for my tests few months ago.

Back to my problem: it is not to read configuration in my service broker, it's to read configuration from an instance method in my service object

As I stated, my service object is currently not inheriting from any base class (well appart System.Object) so I can't access such thing as "base.Service.ServiceConfiguration"

I work arround the problem by storing ServiceConfiguration in a static method but that doesn't help to get things as clean or discoverable as they would be with a clear API.

What I saw in the samples from blackmarket seems to whacky (passing static configuration arround at the initialization of the service broker), I separated theses to a ServiceConfiguration class but still, there is nothing that tells if it is safe to store a static instance of configuration during ServiceBroker.GetConfigSection initialization stage.

Does my service object need to inherit from some base class in the SourceCode base classes to access the configuration?

how does the broker management tool access to instance of the configuration?  

Badge

gauthier,


I have the exact same question, "How can a service object instance gain access to and use the configuration values defined in the service broker?"  Did you solve this problem?  If so, what was the solution?  Thanks.

Reply