Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created February 24, 2011 08:28
Show Gist options
  • Select an option

  • Save thecodejunkie/841923 to your computer and use it in GitHub Desktop.

Select an option

Save thecodejunkie/841923 to your computer and use it in GitHub Desktop.
Implementation of NancyModuleBuilder
public class DefaultNancyModuleBuilders : INancyModuleBuilder
{
private readonly INancyModuleCatalog moduleCatalog;
private readonly IViewFactory viewFactory;
private readonly ResponseFormatter responseFormatter;
public DefaultNancyModuleBuilders(INancyModuleCatalog moduleCatalog, IViewFactory viewFactory, ResponseFormatter responseFormatter)
{
this.moduleCatalog = moduleCatalog;
this.viewFactory = viewFactory;
this.responseFormatter = responseFormatter;
}
/// <summary>
/// Builds a fully configured <see cref="NancyModule"/> instance, based upon the provided <paramref name="moduleKey"/>.
/// </summary>
/// <param name="moduleKey">The key of the module to build.</param>
/// <param name="context">The current request context.</param>
/// <returns>A fully configured <see cref="NancyModule"/> instance.</returns>
public NancyModule GetConfiguredModule(string moduleKey, NancyContext context)
{
var module =
this.moduleCatalog.GetModuleByKey(moduleKey, context);
module.Context = context;
module.Response = this.responseFormatter;
module.View = this.viewFactory;
return module;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment