-
Notifications
You must be signed in to change notification settings - Fork 34
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
Doesn't work with .net core 2.0 #39
Comments
Do you mean your UT doesn’t work? Or the deployed App doesn’t work? |
If it’s UT only, try workaround it by manually loading the factory module. |
I don't know what you mean by UT. However I did discover that if I add new FuncModule() to my Kernel then it works. This is described here: It doesn't mention this as being necessary for .net Core only for Silverlight. However it does fix my issue. |
I mean unit test |
OK, no not unit test, we don't use Ninject for our unit tests, We use Ninject only the composition root of our app. Unit testing is accomplished by constructor injecting mocks manually. This is a .net core console app, running from visual studio. |
My team is also running into this problem using Ninject 3.3.4 and Ninject.Extensions.Factory 3.3.2 with .Net Core 2.0. Interestingly, we only need to load FuncModule() when running on Windows. If we run the same application in Linux, it fails due to duplicate modules being loaded. To make it work on both, you can do something like:
|
I think I understand what's happening now. When building in VS or using "dotnet build", the resulting build does not include dependencies. Instead, the Core runtime relies on the Nuget cache to load them. Ninject probably looks for modules in the local directory to load dynamically which is why you have to manually load the Factory module. When using "dotnet publish", the build directory has a stand alone version of the application with all dependencies in the local directory. This allows Ninject to discover and load the module dynamically. I'm using the following which seems to be working in all cases:
If this were added to documentation somewhere, this issue can probably be closed as I think it is working as intended. |
While I can appreciate the insight @aerotog provided, this change in how .Net Core copies build output (or lack thereof) breaks the auto-discovery of Ninject extensions as well. Performing a "publish" fixes that issue, but creates a new one by removing the ability to easily run and debug the application using the Visual Studio interface. "Publish" is a workaround, but I'm curious if the Ninject team has a solution to the extension loading dilemma presented here. |
try <PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup> |
Thanks @scott-xu, that did the trick. |
I have:
I have converted a working project from .net 4.6.1 to .net standard 2.0 and .net core 2.0. Now none of my Ninject.Extensions.Factory stuff works.
The Func<> automatic bindings are not happening, I get a runtime error saying it couldnt' find a binding for Func (I have worked around this be automatically binding all the Func<T's> that I need.
The interface factories like the following:
Bind<IWorkerThreadFactory>().ToFactory();
Result in a runtime error as follows:
I have triple checked that my projects are using Ninject.Extensions.Factory 3.3.2 via nuget.
The text was updated successfully, but these errors were encountered: