Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

ConfigureServices being called 3 times #266

Closed
sujitdmello opened this issue May 11, 2015 · 8 comments
Closed

ConfigureServices being called 3 times #266

sujitdmello opened this issue May 11, 2015 · 8 comments
Assignees
Milestone

Comments

@sujitdmello
Copy link

Not sure when this started happening but I’m on the latest Beta5 bits now and even using the simple HelloWeb app, I noticed that if I have a ConfigureServices method in the Startup class, it is called exactly 3 times when running dnx . kestrel. Am I wrong in expecting it to be called just once? Or do I have an issue with my setup?

The Configure method is called once as expected.

@HaoK
Copy link
Member

HaoK commented May 11, 2015

Can you share the Startup class? I don't see this behavior when running, for example the CookieSample: https://github.com/aspnet/Security/tree/dev/samples/CookieSample

@Tragetaschen
Copy link
Contributor

Looking at the code, the EnsureApplicationServices method in HostingEngine.cs does not shurtcut if _applicationServices is already set. So in Program.cs, the call to Start and twice to the ApplicationServices property will each call the delegate eventually.

This was introduced in 77e2dc2.

@HaoK
Copy link
Member

HaoK commented May 11, 2015

Ah yeah that's definitely it, good catch, I'll fix and add tests today

@HaoK
Copy link
Member

HaoK commented May 11, 2015

1354d66

@HaoK HaoK closed this as completed May 11, 2015
@davidfowl davidfowl added this to the 1.0.0-beta5 milestone May 11, 2015
@Eilon Eilon reopened this May 12, 2015
@Eilon
Copy link
Member

Eilon commented May 12, 2015

Re-opening because apparently this still repros for @sujitdmello .

@Eilon
Copy link
Member

Eilon commented May 12, 2015

From @sujitdmello 👍

Assuming the fix made it to the latest build, that did not address my specific issue. I got the latest unstable runtime and did a dnu restore but still seeing 3 identical ConfigureServices invocations with this callstack. I verified with ProcMon that there is only one DNX process starting:

ConfigureServices
   at KWebStartup.Startup.ConfigureServices(IServiceCollection services)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNet.Hosting.Startup.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices)
   at Microsoft.AspNet.Hosting.Startup.ConfigureServicesBuilder.<>c__DisplayClass4_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureApplicationServices()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.get_ApplicationServices()
   at Microsoft.AspNet.Hosting.Program.Main(String[] args)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
   at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at dnx.host.Bootstrapper.RunAsync(List`1 args)
   at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args)
   at dnx.host.RuntimeBootstrapper.Execute(String[] args)
   at DomainManager.Main(Int32 argc, String[] argv)

@Tratcher
Copy link
Member

The CI build just passed 15 minutes ago. Try again @sujitdmello.

@sujitdmello
Copy link
Author

Perfect! Just did a dnu restore and it worked! Just one call to ConfigureServices. Thanks guys!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants