Topics: Writing modules
Aug 5, 2011 at 1:30 PM
Edited Aug 5, 2011 at 1:38 PM

Hey I had the idea of an Settingsmanager module.

therefor I created a module with Setting(String)/Value(String) as Table.

E.g we could have gridpagesize/10 as Setting/value pair.

now i want to be able in other modules to get these settings via Service of that module. that works so far.

      public SettingsRecord GetSetting(string settingName)
            return _SettingsRepository.Get(x => x.SettingName == settingName);

my question is now: If I create the empty module, nothing is in. how would you handle it, that it automatically created default entries for all required settings.

i thought about something like @T(string) so that i could even use settings that arent defined as of yet.

will this be easily realizable? what do you think

and how can i achieve that all elements will be written into the database on initialization ;))

Aug 5, 2011 at 4:14 PM
Edited Aug 5, 2011 at 4:15 PM

You might want to read this first:

Going back to your original question: There is an interface you could implement called IFeatureEventHandler. This lets you hook on to various events as a feature is enabled or disabled in your site. Here you can set defaults.

Another approach might be to write some recipe commands to do it by inheriting from DefaultOrchardCommandHandler, then you can specify defaults in your recipe.

You should back this up with hard-coded sensible defaults, for instance you might have a method called

object GetConfigValue(string name)
    // Get config

You should allow this to take a default value:

object GetConfigValue(string name, object deflt)
          // Get config
      catch(Exception e)
          return deflt;

However, I would seriously consider using the existing settings mechanisms. The biggest problem I see with your approach is that will a setting ALWAYS consist of a name value pair? What if you need to store complex information (and you might not want to store it as XML or JSON in your database, that's naughty ;-). How would you maintain strongly typed settings? (E.g. how do you tell if a setting is a string or a number?)

Aug 5, 2011 at 5:24 PM

hey kobowi,

thanks for your answer!

looks as if this is what i need, i have to go threw it, which will take some time to understand :)

but you're right, always using a name value wouldn't be what i want.

i will post later what i learned and thinkn of it.

orchard is really a wonderful thing