kernel.Bind<ISqlServerConnectionContext, IConnectionContext>().ToMethod(x => { var newConnectionContext = new SqlServerConnectionContext(connectionString); newConnectionContext.ProductID = productID; newConnectionContext.Open(); return newConnectionContext; }).InRequestScope();
You need either Ninject.Web.WebApi.WebHost or Ninject.Web.WebApi.SelfHost depending on how you host web api
--
You received this message because you are subscribed to the Google Groups "ninject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+u...@googlegroups.com.
To post to this group, send email to nin...@googlegroups.com.
Visit this group at http://groups.google.com/group/ninject.
For more options, visit https://groups.google.com/groups/opt_out.
WebHost does not add any assemblies that’s correct. It integrates Ninject into the solution by adding Ninject to the App_Start of the project.
Your problem could be that the current prerelease is built against WebApi 2. Since you have MVC4 I assume you are using WebApi 1.0. In that case you can either add assembly rebinds back to WebApi 1 assembly versions (I didn’t check if that works) or download the sources and build against WebApi 1.
Older versions of the WebApi had a problem with the nuget deployment. Also have a look at the Sample Applications on github.
Just verified that everything works properly:
1. Create new WebApi 1.0 using VS Wizard
2. Changed:
WebApiConfig.Register(GlobalConfiguration.Configuration);
to
GlobalConfiguration.Configure(WebApiConfig.Register);
3. Uninstall FixedDisplayModes NuGet
Uninstall-Package -Id Microsoft.AspNet.Mvc.FixedDisplayModes
4. Update all NuGetPackages to latest
5. Install Ninject.Web.WebApi.WebHost –pre
6. Change ValuesController to require dependency
7. Configure Ninject with a binding for the dependency InRequestScope
8. Run and Navigate to /api/Values
Results:
· A new instance of the dependency is injected for each call.
· The depencency is disposed at the end of the call
I really can’t reproduce your problems. Don’t know what you are doing differently.
The only thing that I found is that you can’t add a dependency to the HomeController because it is MVC and not WebApi. To solve this you have to install Ninject.Mvc.
Also I don’t know why you think it references MVC 4.1. Following all links on nuget.org shows that it does not and it doesn’t install it either on my machine. Seems that nuget is doing something odd in your case. E.g. installing another than the latest package or taking an old nuspec.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+unsubscribe@googlegroups.com.
To post to this group, send email to
Now I see the problem. You are not using the latest version of Ninject.Web.WebApi
This is what you have to use:
http://www.nuget.org/packages/Ninject.Web.WebApi.WebHost/3.0.2-unstable-9022
http://www.nuget.org/packages/Ninject.Web.WebApi/3.0.2-unstable-9022
Those packages are built against Web Api 2.0 (5.0). But are compatible with 2.1 (5.1)
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+u...@googlegroups.com.
To post to this group, send email to
Visit this group at http://groups.google.com/group/ninject.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "ninject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+u...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+unsubscribe@googlegroups.com.
To post to this group, send email to
Visit this group at http://groups.google.com/group/ninject.
For more options, visit https://groups.google.com/groups/opt_out.
It seems you messed up your assembly references. Try to remove everything from you packages.config, package folder and assembly references and get it again.
Also download https://github.com/ninject/Ninject.Web.WebApi/tree/master/src/SampleApplication and make sure you have everything like there.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+u...@googlegroups.com.
To post to this group, send email to nin...@googlegroups.com.
Visit this group at http://groups.google.com/group/ninject.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "ninject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+u...@googlegroups.com.
To post to this group, send email to nin...@googlegroups.com.
Visit this group at http://groups.google.com/group/ninject.
For more options, visit https://groups.google.com/groups/opt_out.