SiteSettings for your Epi Site

A neat way to configure site settings with DI StructureMap in Episerver

Warning: A non-numeric value encountered in /storage/content/29/141529/ on line 27

Published 2nd sept 2020

I like this approach, site settings thru Dependency Injection (DI). Im fully aware that this subject is nothing new, and EMVP collegues have been blogged about this for ages.


However, none are using Interface and DI to locate the settings (except Linus’ addon, but thats another approach).


Example 1 – preferable

Example 2 – get StartPage as ISiteSettings

Example 3, multiple ISiteSettings in one site

Make an Interface ISiteSettings

Add your settings properties into this Interface

SiteSetting needs to derive from IContent since you later want to use the contentLoader to load ISiteSettings

Implement Interface as a Partial class

Use C# Partial Class to separate the startpage properties from the SiteSettings properties into two files

What you need is to put key word “partial” into both object implementation, important to use same class name in same namespace.

[ContentType(GUID = "x")]
public partial class StartPage : SitePageData, IContent


Note: It is the StartPage that is derived from PageData that implements IContent and not the StartPage.ISiteSettings

Register ISiteSettings to StructureMap with Registry

The Registry will be scanned and configured if you configure StructureMap with a IConfigurableModule like this:

Multisite scenario

Yes! by using ContentReference.StartPage in registry or SiteDefinition.Current.StartPage it will contextualy return the right settings.

Note: remember to set * in website management i Epi Admin to assign the default website if no HttpContext exists (in scheduled jobs ContentReference.StartPage will return the default website startpage if * is configured)

About the author

Luc Gosso
– Independent Senior Web Developer
working with Azure and Episerver

Twitter: @LucGosso

Like it? please up vote

Leave a Reply

Your email address will not be published. Required fields are marked *