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

Conversation

jchannon
Copy link
Member

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#L116

So 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

@@ -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.

@phillip-haydon
Copy link
Member

Strange issue, does appear to be a bug. Easy to reproduce and fix does in need fix it.

Just find it strange that this popped up now rather than a long time ago....

Also..

bad pr

@khellang
Copy link
Member

What about RequestScopedCollectionTypes?

@jchannon
Copy link
Member Author

Yup looks like that needs some attention. Please hold..........

@jchannon
Copy link
Member Author

Added to repro project. Collection is showing 3 items, I was expecting 0 on RequestStartup

@jchannon
Copy link
Member Author

Adding a similar fix to RequestScopedCollectionTypes like I did for RequestScopedTypes results in 5 registrations in RequestStartup

Any ideas?

@jchannon
Copy link
Member Author

If I do container.Resolve<IEnumerable<IFoo>>() instead in RequestStartup it shows 4 registrations 😟

@jchannon
Copy link
Member Author

This solved it:

        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            //base.ConfigureApplicationContainer(container);
        }

@phillip-haydon
Copy link
Member

If Travis gives the ok. I'm happy with this PR, @khellang can merge since he poked his head in.

@jchannon
Copy link
Member Author

@khellang do your thing!

@khellang
Copy link
Member

Can you guarantee that we don't break anyone with this?

@jchannon
Copy link
Member Author

No

@jchannon
Copy link
Member Author

Calling "grumps & junks" @NancyFx/owners

@jchannon jchannon added this to the 1.0 Alpha milestone Sep 8, 2014
@horsdal
Copy link
Member

horsdal commented Sep 23, 2014

why no unit test?

grumpydev added a commit that referenced this pull request Nov 19, 2014
requestscopedtype fix being overwritten
@grumpydev grumpydev merged commit 43cdb8e into NancyFx:master Nov 19, 2014
@grumpydev grumpydev modified the milestones: 1.0 Alpha, 1.0 Feb 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants