Created
January 24, 2017 13:10
-
-
Save grumpydev/c93281668b32e295ef967e2f966f4e6a to your computer and use it in GitHub Desktop.
For funsies, lowest common denominator nancy bootstrapper with no container at all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Globalization; | |
using Nancy; | |
using Nancy.Bootstrapper; | |
using Nancy.Conventions; | |
using Nancy.Culture; | |
using Nancy.Diagnostics; | |
using Nancy.ErrorHandling; | |
using Nancy.Hosting.Aspnet; | |
using Nancy.Localization; | |
using Nancy.ModelBinding; | |
using Nancy.Responses.Negotiation; | |
using Nancy.Routing; | |
using Nancy.Routing.Constraints; | |
using Nancy.Routing.Trie; | |
using Nancy.Validation; | |
using Nancy.ViewEngines; | |
namespace DumbassBootstrapper | |
{ | |
/// <summary> | |
/// Lowest common denominator bootstrapper with no container | |
/// </summary> | |
public class Dumbo : INancyBootstrapper, INancyModuleCatalog | |
{ | |
public void Dispose() | |
{ | |
} | |
public void Initialise() | |
{ | |
} | |
public INancyEngine GetEngine() | |
{ | |
var engine = new NancyEngine(new DefaultRequestDispatcher(new DefaultRouteResolver(this, new DefaultNancyModuleBuilder(new DefaultViewFactory(new DefaultViewResolver(new DefaultViewLocator(new FileSystemViewLocationProvider(new AspNetRootPathProvider()),new List<IViewEngine>() ),new ViewLocationConventions(new List<Func<string, object, ViewLocationContext, string>>()) ),new List<IViewEngine>(),new DefaultRenderContextFactory(new DefaultViewCache(), new DefaultViewResolver(new DefaultViewLocator(new FileSystemViewLocationProvider(new AspNetRootPathProvider()),new List<IViewEngine>() ),new ViewLocationConventions(new List<Func<string, object, ViewLocationContext, string>>()) ),new ResourceBasedTextResource(new ResourceAssemblyProvider()) ),new ViewLocationConventions(new List<Func<string, object, ViewLocationContext, string>>()),new AspNetRootPathProvider() ),new DefaultResponseFormatterFactory(new AspNetRootPathProvider(), new List<ISerializer>()), new DefaultModelBinderLocator(new List<IModelBinder>(),new DefaultBinder(new List<ITypeConverter>(),new List<IBodyDeserializer>(),new DefaultFieldNameConverter(), new BindingDefaults()) ),new DefaultValidatorLocator(new List<IModelValidatorFactory>()) ),new RouteCache(this, new DefaultNancyContextFactory(new DefaultCultureService(new CultureConventions(new List<Func<NancyContext, CultureInfo>>())), new DefaultRequestTraceFactory(), new ResourceBasedTextResource(new ResourceAssemblyProvider())), new DefaultRouteSegmentExtractor(), new DefaultRouteDescriptionProvider(), new DefaultCultureService(new CultureConventions(new List<Func<NancyContext, CultureInfo>>())),new List<IRouteMetadataProvider>() ),new RouteResolverTrie(new TrieNodeFactory(new List<IRouteSegmentConstraint>())) ),new List<IResponseProcessor>(), new DefaultRouteInvoker(new DefaultResponseNegotiator(new List<IResponseProcessor>(),new AcceptHeaderCoercionConventions(new List<Func<IEnumerable<Tuple<string, decimal>>, NancyContext, IEnumerable<Tuple<string, decimal>>>>()) )),new DefaultResponseNegotiator(new List<IResponseProcessor>(), new AcceptHeaderCoercionConventions(new List<Func<IEnumerable<Tuple<string, decimal>>, NancyContext, IEnumerable<Tuple<string, decimal>>>>())) ),new DefaultNancyContextFactory(new DefaultCultureService(new CultureConventions(new List<Func<NancyContext, CultureInfo>>())), new DefaultRequestTraceFactory(), new ResourceBasedTextResource(new ResourceAssemblyProvider())), new List<IStatusCodeHandler>(),new DefaultRequestTracing(), new DefaultStaticContentProvider(new AspNetRootPathProvider(), new StaticContentsConventions(new List<Func<NancyContext, string, Response>>())),new DefaultResponseNegotiator(new List<IResponseProcessor>(), new AcceptHeaderCoercionConventions(new List<Func<IEnumerable<Tuple<string, decimal>>, NancyContext, IEnumerable<Tuple<string, decimal>>>>()))) | |
{ | |
RequestPipelinesFactory = RequestPipelinesFactory | |
}; | |
return engine; | |
} | |
private IPipelines RequestPipelinesFactory(NancyContext nancyContext) | |
{ | |
return new Pipelines(); | |
} | |
public IEnumerable<INancyModule> GetAllModules(NancyContext context) | |
{ | |
return new[] {new MyModule()}; | |
} | |
public INancyModule GetModule(Type moduleType, NancyContext context) | |
{ | |
if (moduleType == typeof(MyModule)) | |
{ | |
return new MyModule(); | |
} | |
throw new InvalidOperationException("No module found!"); | |
} | |
} | |
public class MyModule : NancyModule | |
{ | |
public MyModule() | |
{ | |
Get["/"] = _ => "Hello!"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment