Class SettingsRepository<T>
The SettingsRepository is used to persist settings to one of DNNs internal settings stores
Inheritance
Implements
Namespace: DotNetNuke.Entities.Modules.Settings
Assembly: DotNetNuke.dll
Syntax
public abstract class SettingsRepository<T> : object, ISettingsRepository<T> where T : class, new()
Type Parameters
Name | Description |
---|---|
T |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
Constructors
| Improve this Doc View SourceSettingsRepository()
Initializes a new instance of the SettingsRepository<T> class.
Declaration
protected SettingsRepository()
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
Properties
| Improve this Doc View SourceMappingCacheKey
Gets cache key for this class. Used for parameter mapping storage as well as entire class persistence.
Declaration
protected virtual string MappingCacheKey { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
Methods
| Improve this Doc View SourceCreateMapping()
Rebuilds parameter mapping of the class.
Declaration
protected virtual IList<ParameterMapping> CreateMapping()
Returns
Type | Description |
---|---|
IList<ParameterMapping> | List of parameters. |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
GetSettings(ModuleInfo)
Retrieve module settings. This can optionally include TabModule settings, Portal settings and host settings as well. Note the result is cached.
Declaration
public T GetSettings(ModuleInfo moduleContext)
Parameters
Type | Name | Description |
---|---|---|
ModuleInfo | moduleContext | Your module's context. |
Returns
Type | Description |
---|---|
T | Your settings class. |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
GetSettings(Int32)
Retrieve portal/host settings. This will ignore Module and TabModule settings. Note the result is cached.
Declaration
public T GetSettings(int portalId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | portalId | The portal ID for which to retrieve the settings. |
Returns
Type | Description |
---|---|
T | Your settings class. |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
LoadMapping()
Retrieves the parameter mapping from cache if still there, otherwise recreates it.
Declaration
protected IList<ParameterMapping> LoadMapping()
Returns
Type | Description |
---|---|
IList<ParameterMapping> | List of parameters. |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
SaveSettings(ModuleInfo, T)
Save your module's settings. This can optionally include TabModule settings, Portal settings and host settings as well.
Declaration
public void SaveSettings(ModuleInfo moduleContext, T settings)
Parameters
Type | Name | Description |
---|---|---|
ModuleInfo | moduleContext | Your module's context. |
T | settings | Your settings class. |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage
SaveSettings(Int32, T)
Save your settings. Module and TabModule settings will be ignored. Only Portal settings and host settings will be saved.
Declaration
public void SaveSettings(int portalId, T settings)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | portalId | Your portal Id for these settings. |
T | settings | Your settings class. |
Remarks
The SettingsRepository allows you to write concise classes for persisting settings to either ModuleSettings, TabModuleSettings or PortalSettings. All you need to do is to implement a static retrieval method (GetSettings in the sample below) and a storage method (SaveSettings below) on a Repository that is typed to your class (MyModuleSettingsRepository below). You can then label each settings you need by providing the right attribute to each property.
Setting up the settings class
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Settings;
public class MyModuleSettings
{
[ModuleSetting]
public int Foo { get; set; } = -1;
[ModuleSetting]
public string Bar { get; set; } = "My default string";
[TabModuleSetting]
public bool Baz { get; set; } = true;
public static MyModuleSettings GetSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
return repo.GetSettings(module);
}
public void SaveSettings(ModuleInfo module)
{
var repo = new MyModuleSettingsRepository();
repo.SaveSettings(module, this);
}
}
public class MyModuleSettingsRepository : SettingsRepository<MyModuleSettings>
{
}
Consuming the settings in your module
Once you have the settings class you can use this anywhere in your code. The most powerful way is to add this to a base class underlying your front end code. If working in an MVC type scenario you could create a class that inherits from DnnController (e.g. MyModuleController) that your controllers inherit from:
public class HomeController : MyModuleController
Then, in MyModuleController you could add the following snippet:
private MyModuleSettings _settings;
public MyModuleSettings Settings
{
get { return _settings ?? (_settings = MyModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
Now in any of your controllers you can access these settings using Settings.Foo
and Settings.Bar
, etc. You can use a similar approach for the WebPage/WebPage