A configuration source in OpenRasta is used to define what resources are available, and where (think routing in ASP.NET).
Unfortunately, once you have more than a few endpoints it rapidly becomes unwieldy.
A few of my colleagues started pulling chunks of configuration out into static methods on separate classes, which led towards… the final ConfigurationSource!
public class ConfigurationSource : IConfigurationSource { private readonly IEnumerable<IDefineResources> _resourceDefinitions; public ConfigurationSource(IDefineResources[] resourceDefinitions) { _resourceDefinitions = resourceDefinitions; } public void Configure() { using (OpenRastaConfiguration.Manual) { foreach (var resourceDefinition in _resourceDefinitions) { resourceDefinition.DefineResources(); } } } }
This allows you to implement IDefineResources:
public interface IDefineResources { void DefineResources(); }
For example:
public class MyResourceDefinitions : IDefineResources { public void DefineResources() { ResourceSpace.Has.ResourcesOfType<MyResource>() .AtUri("some/resource/{id}") .HandledBy<MyHandler>() .AsXmlSerializer .ForMediaType(MediaType.Xml); } }
And, as long as the container knows about it, your resources will be defined.
This means you can even define resources outside the main project, allowing you to move in the direction of modular, composable applications.