Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Minor tweaks and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
grumpydev committed Oct 26, 2011
1 parent fd5ad87 commit 941165d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
15 changes: 11 additions & 4 deletions src/Nancy.Demo.Authentication.Forms/FormsAuthBootstrapper.cs
Expand Up @@ -7,21 +7,28 @@ public class FormsAuthBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
{
}

protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, Bootstrapper.IPipelines pipelines)
{
// We don't call "base" here to prevent auto-discovery of
// types/dependencies
}

protected override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer container)
{
base.ConfigureRequestContainer(container);

// Here we register our user mapper as a per-request singleton.
// As this is now per-request we could inject a request scoped
// database "context" or other request scoped services.
container.Register<IUserMapper, UserDatabase>();
}

protected override void RequestStartup(TinyIoC.TinyIoCContainer requestContainer, Bootstrapper.IPipelines pipelines)
{
// At request startup we modify the request pipelines to
// include forms authentication - passing in our now request
// scoped user name mapper.
//
// The pipelines passed in here are specific to this request,
// so we can add/remove/update items in them as we please.
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nancy.Demo.Authentication.Forms/Views/secure.cshtml
Expand Up @@ -8,6 +8,6 @@

<br />
<br />
<a href="/logout">Logout</a>
<a href="@Url.Content("~/logout")">Logout</a>
</body>
</html>
10 changes: 10 additions & 0 deletions src/Nancy.Hosting.Aspnet/DefaultNancyAspNetBootstrapper.cs
Expand Up @@ -42,6 +42,16 @@ public override sealed NancyModule GetModuleByKey(string moduleKey, NancyContext
return this.ApplicationContainer.Resolve<NancyModule>(moduleKey);
}

/// <summary>
/// Creates and initializes the request pipelines.
/// </summary>
/// <param name="context">The <see cref="NancyContext"/> used by the request.</param>
/// <returns>An <see cref="IPipelines"/> instance.</returns>
protected override sealed IPipelines InitializeRequestPipelines(NancyContext context)
{
return base.InitializeRequestPipelines(context);
}

/// <summary>
/// Configures the container using AutoRegister followed by registration
/// of default INancyModuleCatalog and IRouteResolver.
Expand Down
15 changes: 0 additions & 15 deletions src/Nancy/Bootstrapper/IRequestPipelinesFactory.cs

This file was deleted.

21 changes: 18 additions & 3 deletions src/Nancy/Bootstrapper/NancyBootstrapperBase.cs
Expand Up @@ -14,7 +14,7 @@
/// </summary>
/// <typeparam name="TContainer">IoC container type</typeparam>
[SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Abstract base class - properties are described differently for overriding.")]
public abstract class NancyBootstrapperBase<TContainer> : INancyBootstrapper, INancyModuleCatalog, IRequestPipelinesFactory
public abstract class NancyBootstrapperBase<TContainer> : INancyBootstrapper, INancyModuleCatalog
where TContainer : class
{
/// <summary>
Expand All @@ -28,6 +28,11 @@ public abstract class NancyBootstrapperBase<TContainer> : INancyBootstrapper, IN
/// </summary>
private readonly NancyConventions conventions;

/// <summary>
/// Application pipelines.
/// Pipelines are "cloned" per request so they can be modified
/// at the request level.
/// </summary>
protected IPipelines ApplicationPipelines { get; private set; }

/// <summary>
Expand Down Expand Up @@ -297,7 +302,7 @@ public INancyEngine GetEngine()

var engine = this.GetEngineInternal();

engine.RequestPipelinesFactory = this.CreateRequestPipeline;
engine.RequestPipelinesFactory = this.InitializeRequestPipelines;

return engine;
}
Expand All @@ -321,7 +326,12 @@ public override sealed int GetHashCode()
return base.GetHashCode();
}

public virtual IPipelines CreateRequestPipeline(NancyContext context)
/// <summary>
/// Creates and initializes the request pipelines.
/// </summary>
/// <param name="context">The <see cref="NancyContext"/> used by the request.</param>
/// <returns>An <see cref="IPipelines"/> instance.</returns>
protected virtual IPipelines InitializeRequestPipelines(NancyContext context)
{
var requestPipelines =
new Pipelines(this.ApplicationPipelines);
Expand Down Expand Up @@ -440,6 +450,11 @@ private IEnumerable<TypeRegistration> GetAdditionalTypes()
return new[] { new TypeRegistration(typeof(IRootPathProvider), this.RootPathProvider) };
}

/// <summary>
/// Gets any additional instance registrations that need to
/// be registered into the container
/// </summary>
/// <returns>Collection of InstanceRegistation types</returns>
private IEnumerable<InstanceRegistration> GetAdditionalInstances()
{
return new[] { new InstanceRegistration(typeof(CryptographyConfiguration), this.CryptographyConfiguration) };
Expand Down
Expand Up @@ -63,11 +63,11 @@ public override sealed NancyModule GetModuleByKey(string moduleKey, NancyContext
}

/// <summary>
/// Creates and initializes a request pipeline.
/// Creates and initializes the request pipelines.
/// </summary>
/// <param name="context">The <see cref="NancyContext"/> used by the request.</param>
/// <returns>An <see cref="IPipelines"/> instance.</returns>
public override IPipelines CreateRequestPipeline(NancyContext context)
protected override sealed IPipelines InitializeRequestPipelines(NancyContext context)
{
var requestContainer =
this.GetRequestContainer(context);
Expand Down
1 change: 0 additions & 1 deletion src/Nancy/Nancy.csproj
Expand Up @@ -91,7 +91,6 @@
<Compile Include="Bootstrapper\CollectionTypeRegistration.cs" />
<Compile Include="Bootstrapper\IPipelines.cs" />
<Compile Include="Bootstrapper\InstanceRegistration.cs" />
<Compile Include="Bootstrapper\IRequestPipelinesFactory.cs" />
<Compile Include="Bootstrapper\IStartup.cs" />
<Compile Include="Bootstrapper\NancyInternalConfiguration.cs" />
<Compile Include="Bootstrapper\Pipelines.cs" />
Expand Down

0 comments on commit 941165d

Please sign in to comment.