-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated to support WebApi RC #1
Conversation
Doesnt let me uncommit the changes made to WebApiModule.cs
Unfortunately your dependency resolver implementation is not correct. That way all object are singletons within the scope. What you want is that just objects InRequestScope are affected by the scope. |
Ok. I'll fix that and do another pull request. (And clean up the commits while I'm at it) What about the nuget package restore, iisexpress and line endings commits? Should I leave them out? |
Fixed. I noticed there is another pull request that basically does the same thing. (Probably looked at the same articles) :-) |
Whats the current status on this pull request? |
Status is that no-one seems to know where Remo Gloor is... :S |
I'm hoping this gets accepted and pushed to nuget...I've ended up rolling my own, but I would certainly prefer using this package. |
I already posted it up on NuGet while I wait for Remo to release a proper version. |
Hy Remo got married two weeks ago and is currently on a honeymoon trip. I'm in vacation too (althoug not marriage related). Maybe Ian can merge this. I will contact him. Daniel Am 30.08.2012 um 09:48 schrieb Ove Andersen [email protected]:
|
Cool! Congratulations to Remo then! :-) Would be awesome to have an official release of the Ninject WebAPI package. |
I can understand! I have the rights to merge, Ian and others also. Releasing is Remo's job :( but I'm only occasionally online and have no time to do it properly. But I contacted Ian... Am 30.08.2012 um 10:13 schrieb Ove Andersen [email protected]:
|
I'll try to review and integrate this weekend. |
I don't understand that impl either. I'd stick with the dependency resolver code from the previous version for that part. @idavis I expect not to have any Internet connection before Sunday and no regular connection for two weeks more. |
The kernel is the correct resolution root at least for IIS hosting When it comes to self hosting things change quite a bit. I was working Also this solution won't be backward compatible to this pull request. |
The scoping mechanism is a cleanup system. The request-local scope created by Web API is how the controller (and all its dependent services) will get resolved; the scope will be disposed when the request is completed. |
@idavis Yeah. I noticed now the comment is wrong in the Dispose function. Line 35 should have been like this: "We don't want Ninject to dispose the kernel, as .NET handles this for us". Also, line 51 should have been removed. |
@idavis The implementation that @PProvost made looks like it works, but unfortunately makes all objects singletons within the scope. (As noted by @remogloor => #1 (comment)). |
@idavis As for swallowing the exception, I think I agree with you. I've updated the fork in that regard. |
As for exceptions, the contract of the dependency resolver and dependency scope interfaces it that they should NEVER throw. GetService() should return null when it cannot find a service, and GetServices() should return a non-null empty collection when it cannot find any services. |
@azzlack, based on @bradwilson's and @remogloor's advice, I think we need to change the public class NinjectDependencyScope : IDependencyScope
{
private readonly IResolutionRoot resolutionRoot;
internal NinjectDependencyScope(IResolutionRoot resolutionRoot)
{
Contract.Assert(resolutionRoot != null);
this.resolutionRoot = resolutionRoot;
}
public void Dispose()
{
// Do nothing.
}
public object GetService(Type serviceType)
{
try
{
return this.resolutionRoot.Get(serviceType);
}
catch (Exception ex)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
try
{
return this.resolutionRoot.GetAll(serviceType);
}
catch (Exception ex)
{
return new object[0];
}
}
} |
You can use TryGet Daniel Am 06.09.2012 um 17:47 schrieb Ian Davis [email protected]:
|
@danielmarbach TryGet only catches |
Have you looked at https://github.com/NServiceBus/NServiceBus/tree/master/src/impl/ObjectBuilder/ObjectBuilder.Ninject ChildContainer also also like a dependency scope. The ninject child container implements DisposeNotifyingObject Daniel Am 06.09.2012 um 18:01 schrieb Ian Davis [email protected]:
|
@idavis Yup. Fixed in new commit. :-) |
@danielmarbach @bartelink Can anyone else verify that this code is working correctly? I'll continue to review other parts of the pull. |
@danielmarbach @idavis Sorry - can't add anything; I hope Daniel can as I don't have a ninject dev space rigged up at the moment (Though I'll need it for work in a few weeks at which time I'll be making the time no matter what :D) |
If TryGet is avoiding the throwing of some exceptions, I'd still use it, even though you need try/catch for the others (purely for performance reasons). If, on the other hand, TryGet is just doing a try/catch itself to mask an unpreventable exception, then it's not worth bothering with. |
From: Brad Wilson [mailto:[email protected]] If TryGet is avoiding the throwing of some exceptions, I'd still use it, even though you need try/catch for the others (purely for performance reasons). If, on the other hand, TryGet is just doing a try/catch itself to mask an unpreventable exception, then it's not worth bothering with. — |
@Idacos I 've been using this code in test and production for 4 weeks, if that is any proof that it works :-) |
Hy together Daniel |
@bradwilson I question the general rule not to throw any exceptions a |
There's really nothing to be done about it now, since the contract is Note that throwing exception during app startup -- which is the most likely |
@bradwilson In that case I'd really rethink the contract for next |
Hi Guys, cheers |
I'm using this branch with MVC4 web api with great success, thanks a lot.
I was getting a lot of first-chance exceptions due to MVC assemblies not being resolved by ninject. I believe TryGet() is preferred here instead of swallowing the exception this way. I sure hope an MVC4 web api feature is release for ninject soon. Thanks for the great work guys. |
Added support for MVC4 final in c0b1a97 |
Any ideas when the NuGet package will be updated :D? |
After updating docu, testing, .... So long you can get a beta version from the teamcity server nuget feed: https://teamcity.bbv.ch/httpAuth/app/nuget/v1/FeedService.svc/ |
A lot of fixes.
You should look at the changes and see if it suits your plans before merging. :-)