Skip to content

Commit

Permalink
Fixed Issue #17: Thread safety issue on Kernel.Inject
Browse files Browse the repository at this point in the history
  • Loading branch information
remogloor committed Sep 17, 2010
1 parent ace9413 commit 126b824
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Ninject/KernelBase.cs
Expand Up @@ -276,7 +276,10 @@ public virtual void Inject(object instance, params IParameter[] parameters)
var request = CreateRequest(service, null, parameters, false, false);
var context = CreateContext(request, binding);

context.Plan = planner.GetPlan(service);
lock (planner)
{

This comment has been minimized.

Copy link
@rjnienaber

rjnienaber Feb 9, 2011

I'm assuming it's okay for the planner to be called more than once? If two threads hit the lock, thread 1 will wait and thread 2 will call GetPlan. Once thread 2 is finished, thread 1 will also call GetPlan.

context.Plan = planner.GetPlan(service);
}

var reference = new InstanceReference { Instance = instance };
pipeline.Activate(context, reference);
Expand Down

0 comments on commit 126b824

Please sign in to comment.