Developer forum

Forum » Dynamicweb 10 » Recommendations / best practices for GlobalSettings and Custom WebApi

Recommendations / best practices for GlobalSettings and Custom WebApi

Mikkel Hammer
Mikkel Hammer
Reply

Hi DW,

I'm working on a DW10 project where I have to setup a custom webapi endpoint, where the fetched values come from custom GlobalSettings fields.

I've looked around the DW10 source code and documentation, to find a simple way to both setup and work with custom endpoints and GlobalSettings.

 

The "problem" that I have, is how to initialize the GlobalSettings fields in a good way, so they are available in the GlobalSettings section via the administration.

The solution I've made so far looks like this, and is working as intended.

But I'd love to hear input on the setup, and if you would have done it differently in any of the parts - since I'm still getting the hang of working with DW10 (which I love so far!) 

 

First of, here's the model i made for GlobalSettings.

I found the "SettingsViewModelBase" class to help with the setup of GlobalSettings fields - which is working as intended.

 

Then in the controller, i call the "AppSettingsDataModel" to fetch values from the GlobalSettings fields - which also works fine.

But here is where I came across the "problem" the first time, which is the GlobalSettings fields didn't get initialized before the custom endpoint was called.

So i looked into where i could do this initialization, which i get into on the next picture.

 

Here's setup I've ended up with the registration of the customapi endpoint (NOTE: The "UseCustomWebApi" method is shown on the next picture below).

But the only "simple/easy" way I found to initialize the GlobalSettings properties, was to just create a new instance of the "AppSettingsDataModel " class.

That way the underlying "SettingService.Load" method would be called, so the GlobalSettings fields are added.

But is this the intended way? I guess i could do the "old" way, of checking if the field exists or not via SystemConfiguration.Instance.GetValue/SetValue - and then settings the default property that that. I kinda feel like it defeats the purpose of the SettingsAttribute.

 

and here's the "UseCustomWebApi" extension method.

 

What are you'r recommendations regarding the setup, and as i mentioned earlier, is there any thing you would have done differently?

Looking forward to your response :)

 

Best regards,

Mikkel Hammer


Replies

 

You must be logged in to post in the forum