dependency injection in net framework
hi all, i understand that in net core we can add dependency injection like this
but this way doesnt seem to work in net framework, can anyone help advise how can we do this in net framework?
27 Replies
im pretty sure you need to add the nuget: Microsoft.Extensions.DependencyInjection
for .net framework
i installed the package, but i got this message esp on this line
do you know why?
because that stuff doesn't exist in .net framework?
i actually following the way that net core registers their services in a web application.. how can we do this in net framework..?
or there's no way we can register our services in net framework..?
you can, you just need to do it in a valid way for .net framework
so referencing anything in .net core makes 0 sense because its more than likely not applicable. Instead look up examples on how to do it in .net framework
https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/configuring-aspnet-web-api
maybe this can help you
it's something along the lines of
sry, i saw that to add the they added into this method, but in the web application doesnt have this Startup class.. do we create it manually?
sorry friend I have literally 0 experience with .net fw
any reason you are using it?
maybe consider going straight to .net 6
if you can
😦 yup.. it's a requirement to use net framework..
keep on pushing then, there probably are people here that still know that ancient framework, moreover know the asp part of it
which was even more rare back then
okay...
i come across an article about dependency injection on net framework mvc https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/hands-on-labs/aspnet-mvc-4-dependency-injection not sure which Bootstrapper.cs class they refer..
ASP.NET MVC 4 Dependency Injection
Note: This Hands-on Lab assumes you have basic knowledge of ASP.NET MVC and ASP.NET MVC 4 filters. If you have not used ASP.NET MVC 4 filters before, we rec...
but i think they're using unity..
anyone please help advise? 😢
https://stackoverflow.com/questions/43311099/how-to-create-dependency-injection-for-asp-net-mvc-5 idk seems reasonable enough from a simple google
Stack Overflow
How to create dependency injection for ASP.NET MVC 5?
Creating Dependency Injection with ASP.NET Core is fairly easy. The documentation explains it very well here and this guy has a killer video to explain it.
However, I want to do the same thing wit...
hi @IEntityTypeConfiguration<Saber> thank you for the reference, i tried to implement it and some of the error message disappear, i havent build the project because net framework can't seem to read the appsettings.json config file (usually net framework use app/web.config).
i research on few websites that read json configuration file using net framework, the solution provides to install microsoft.extensions.* packages, i have done that but doesnt seem to work, do you have any idea why is that so?
add the correct nugets and usings not much more beyond that you can do
i double checked.. it's the correct package when i hover to the IConfigurationRoot..
did you add the Microsoft.Extensions.Configuration.Json nuget
yup.. i double checked the "Installed" part of all packages, it's installed..
i checked the net core version, the .AddJsonFile should extend from IConfigurationBuilder, but the error message on net framework extend from ConfigurationBuilder...
is it because it only supports net framework 4.6.1 version? (currently im using net 4.8 version)
still not working..
ive tried several tutorials and still the same.. is it safe to say that it's impossible to read appsettings json using net framework?
for example : https://benfoster.io/blog/net-core-configuration-legacy-projects
dunno just spent 3 seconds to make a net framework 4.8 project and it works perfectly fine for me, so its clearly on you
wait.. i think it works in console app but not in the web application...
yes.. i retry to create a console app and it works..
wait.. it was on me yes.. i dont know why after i recreate a new project now it's working... omg...
i tried to implement the solution the way they register the services, but when i run the controller i saw that the Interface is not initialized.. even though when i try to debug, the program run through the initialization part like this ... do you have any idea maybe what could be the issue..?