-
Notifications
You must be signed in to change notification settings - Fork 1.5k
requestscopedtype fix being overwritten #1665
Conversation
@@ -14,6 +14,10 @@ namespace Nancy.Bootstrapper | |||
public abstract class NancyBootstrapperWithRequestContainerBase<TContainer> : NancyBootstrapperBase<TContainer> | |||
where TContainer : class | |||
{ | |||
protected NancyBootstrapperWithRequestContainerBase() | |||
{ | |||
this.RequestScopedTypes = new TypeRegistration[0]; |
There was a problem hiding this comment.
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>();
There was a problem hiding this comment.
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[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok fair enough.
There was a problem hiding this comment.
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.
What about |
Yup looks like that needs some attention. Please hold.......... |
Added to repro project. Collection is showing 3 items, I was expecting 0 on RequestStartup |
Adding a similar fix to Any ideas? |
If I do |
This solved it:
|
If Travis gives the ok. I'm happy with this PR, @khellang can merge since he poked his head in. |
@khellang do your thing! |
Can you guarantee that we don't break anyone with this? |
No |
Calling "grumps & junks" @NancyFx/owners |
why no unit test? |
requestscopedtype fix being overwritten
When you have an application wide dependency registered and a request based dependency defined in a
IRegistrations
implemnetation it is not getting picked up.This is because the foreach loop is overriding
RequestScopedTypes
on each iteration here https://github.com/NancyFx/Nancy/blob/master/src/Nancy/Bootstrapper/NancyBootstrapperWithRequestContainerBase.cs#L116So when it registers the request scoped types here there is nothing to register https://github.com/NancyFx/Nancy/blob/master/src/Nancy/Bootstrapper/NancyBootstrapperWithRequestContainerBase.cs#L157
A repro can be seen here https://github.com/jchannon/nancyrequestproj