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

requestscopedtype fix being overwritten #1665

Merged
merged 2 commits into from
Nov 19, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace Nancy.Bootstrapper
public abstract class NancyBootstrapperWithRequestContainerBase<TContainer> : NancyBootstrapperBase<TContainer>
where TContainer : class
{
protected NancyBootstrapperWithRequestContainerBase()
{
this.RequestScopedTypes = new TypeRegistration[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see

this.RequestScopedTypes = Enumerable.Empty<TypeRegistration>();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't do that as it then says it can't convert IEnumerable<TypeRegistration> to TypeRegistration[]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok fair enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do

this.RequestScopedTypes = Enumerable.Empty<TypeRegistration>().ToArray();

not sure that's better than newing the array directly, though.

}
/// <summary>
/// Context key for storing the child container in the context
/// </summary>
Expand Down Expand Up @@ -113,9 +117,9 @@ protected override sealed void RegisterRegistrationTasks(IEnumerable<IRegistrati
applicationRegistrationTask.TypeRegistrations.ToArray();

this.RegisterTypes(this.ApplicationContainer, applicationTypeRegistrations.Where(tr => tr.Lifetime != Lifetime.PerRequest));
this.RequestScopedTypes = applicationTypeRegistrations.Where(tr => tr.Lifetime == Lifetime.PerRequest)
.Select(tr => new TypeRegistration(tr.RegistrationType, tr.ImplementationType, Lifetime.Singleton))
.ToArray();
this.RequestScopedTypes = this.RequestScopedTypes.Concat(applicationTypeRegistrations.Where(tr => tr.Lifetime == Lifetime.PerRequest)
.Select(tr => new TypeRegistration(tr.RegistrationType, tr.ImplementationType, Lifetime.Singleton)))
.ToArray();

var applicationCollectionRegistrations = applicationRegistrationTask.CollectionTypeRegistrations == null ?
new CollectionTypeRegistration[] { } :
Expand Down