ASP.net vnext Dependency Injection - asp.net

I have heard that in the next version of ASP.NET (ASP.NET vnext) there will be dependency injection built into the framework.
Does anyone know more about this?
Will it be unity or a new framework?
Where can I find more information about this?

ASP.NET vNext will have built-in support for dependency injection. It is very basic support that currently supports only constructor injection.
The source repo for ASP.NET vNext's dependency injection logic contains sample implementations of how to wire up several community-built dependency injection systems, including Autofac, Ninject, StructureMap, Unity, and Castle Windsor. However, those are just samples and are not all complete or fully functional.
The idea is that for basic scenarios a developer can use the built-in DI, whereas people with more advanced requirements or if they already have a "favorite" DI system can plug that in instead and get richer features.

It will contain common abstractions for Autofac, Ninject, StructureMap, Unity, Windsor as seen here Dependency Injection github If you see in the Project.Json it has dependencies on these specific frameworks.

Here is instruction how to use Autofac with ASP.NET 5

This blog explains the details on hov to wire up your own container: http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx

Related

Is the Managed Extensibility Framework (MEF) what ASP.NET Core 2 uses internally for IoC?

I am trying to gauge if Managed Extensibility Framework (MEF) is something I can use for extending an ASP.NET Core 2.x MVC website. I saw ExtCore also. My desire is to use it to build infrastructure for plugins in my application.
What I cannot figure out is if MEF is legacy from Silverlight or if MEF is what Core actually uses for it's IoC. I know MEF is in CoreFX, but that's all I know for sure.
I'd like to use MS's IoC DI here if it is viable and not legacy. Is MEF legacy or is it used by Core itself?
Some questions I looked at, most were very old,
Is there a replacement for MEF in .NET Core (or ASP.NET 5)
In ASP.NET Core, does the IoC ASP Startup Class solve what the Managed Extensibility Framework solved with a catalog and container?
(The last one is a question I asked at the end of 2016.)

Differences between .Net Full framework and the .Net Core Framework 4.5 used by K runtime?

I've seen videos introducing ASP.NET vNext and been keeping up with the recent announcement blog posts, but detailed information on what's been stripped from the full framework appears slim. Here's what I think I know so far:
It's much smaller (11MB vs >200MB): http://davidzych.com/2014/05/24/getting-started-with-asp-net-vnext/
Strong naming is gone: http://jeremydmiller.com/2014/06/09/final-thoughts-on-nuget/
It's dumped System.Web
It includes a merged MVC and WebAPI (however I don't believe this is part of the framework itself but rather dependencies that can be specified)
Dependencies are completely managed through project.json, to the extent that the base
Are we basically looking at a framework that basically includes nothing more than what's in mscorlib in the full framework, with all else delivered via package management? And if this is the case, why would one need to target the framework specifically, as described here? http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
The reason they specifically target NET45 in the link you supplied is because AutoFac is built for and has a dependency on .NET 4.5. Without NET45 the code wouldn't compile.
My assumption is that once vNext gets closer and closer to release the Autofac (and StructureMap, and Castle Windsor, and ...) will release a version that targets the cloud optimized framework to remove the dependency.
As far as I understand, .Net Framework is the fully framework we know and love with all the Windows implementations and lots of code we don't normally use, like they explain in some videos an XML parser.
In .NET Core they removed all the unneeded implementations/dependecies and only left the basic ones. which also enables cross platform (not yet), so in the future one could think as the only framework : CORE Framework, and run on any device. Their february community standup give a lots of information and insight on their objectives and goals.
I see this as a transition, when some features are available only on the full Framework while in the futures one might expect to see all features available for .NET Core.
From a Microsoft perspective, if they want to release lets say Entity Framework for mobile (EF7 is aiming at that) they must get rid of all the windows implementations, on EF and it's dependencies (Framework). So they created a non-windows dependency on the framework, which also helps the multiple framework install and remove some problems with updating the framework by having them mostly isolated from the system, lying in the application. New problems will come like multiple copies of the same framework on one machine per application, that's why they are working on something called Smart Sharing.
This post may help you and give you some insight specially this part :
The structure of .NET Core is comprised of two major components which
add to and extend the capabilities of the .NET Framework as follows:
Runtime:
Built on the same codebase as the .Net Framework CLR. Includes the
same GC and JIT (RyuJIT) Does not include features like Application
Domains or Code Access Security. The runtime is delivered on NuGet
(Microsoft.CoreCLR package)
Base class libraries:
Are the same code as the .Net Framework class libraries but do not
contain dependencies so have a smaller footprint. Available on NuGet
(System.* package)
and I guess you already read Introducing .NET Core from Microsoft.
Regarding your concern about specifying a specific framework is because right now, not everything works on Core CLR so you must choose which one to use, or you can target both and use different implementations.
As of right now, CORE only runs on Windows; the mono framework doesn't have a SQLLite provider for entity framework but it does on Core, so you can use an InMemory or Azure EF provider for example, and choose depending on the enviroment your application is running.
As Scott Gu says on the community standup, they envision a future where there's no mono framework or full framework, there's just Core, but that will take time if it ever happens.
I can't find an original source other than a comment by David Fowler (I believe) on a presentation from NDC, but CoreCLR used by the K Runtime is actually a reincarnation of the CLR used by Silverlight 2. It was used because it's small and designed to be cross platform. There is some additional information here: https://stackoverflow.com/a/25720160/113225

Windows 8 and Ninject : Reflection method cannot be used on the current platform

I have a windows 8 app solution and I am using MVVM. So I have the viewModelLocator and that does it's job.
But now I also want ninject to do some dependency injection (since the viewModelLocator is actually a locator, but no DI)
So I went to download the ninject DLL for .net framework 4.5 and try to get an instance of a type from the kernel like this:
DataSource = NinjectKernel.Get<IBudgetTrackerAppDataSource>();
Where the DataSource is a class used throughout the whole app. The problem is when that line is executed, I get the following error:
The API 'System.Reflection.RuntimeMethodInfo.GetParentDefinition()' cannot be used on the current platform
So I think Ninject and Windows 8 are having a fight, so the question is: How can I get past this issue? (Another version of ninject? another DI framework? ...)
To build WinRT apps you can only reference other WinRT assemblies, this is why referencing a .NET 4.5 version of Ninject won't work correctly. It does appear there is a WinRT version of Ninject but it hasn't been released, the source is available on GitHub.
There are a number of IoC frameworks that support WinRT out there. Both Caliburn.Micro and MVVM Light come with there own containers as well as MetroIoC.

N-tier web application sample with Ninject?

I am trying to learn how to use dependency injection and Ninject. I've been reading blog posts on the topic and Mark Seeman's book "Dependency Injection in .NET". While I have a general understanding of DI, I have troubles understanding how to organize code in a n-tier web application.
Does anyone know of a project sample that I can download, or a blog post to review? Even better if the sample is based on Ninject and MVC3.
NerdDinner is a sample ASP.NET MVC project, and it has been updated to MVC 3: http://nerddinner.codeplex.com/
There are modified versions of the old MVC 2 version that use Ninject and Unity for dependency injection: http://nerddinneraddons.codeplex.com/ The author of those projects provided a different sample application using MVC 3 and Entity Framework 4.1: http://efmvc.codeplex.com/ but used AutoFac rather than Ninject for dependency injection.
There's S#arp Lite, a light version of S#arp Architecture recently started by S#arp Architecture's original author.
His introductory blogposts:
Introducing S#arp Lite ...S#arp Architecture's pompous little sister
S#arp Lite: The Basics

spring framework & asp.net mvc

I heard there is a port of spring framework to .Net framework which is called spring.net.
Anyone can compare those two frameworks? If design the system, which one is prefered or both can be used.
Spring is for Java, Spring.NET is a .NET port of the Java framework.
See the overview page for a summary of the modules it implements.
You can't use both since they are written for different platforms. If you're designing the system and have the freedom to choose which platform you're implementing in, you can choose either Spring for a Java implementation or Spring.NET for a .NET implementation.
They are slowly getting a bit different, especially with the support for .NET specific things, such as WCF.
If you're going to decide to implement in .NET/Java I would take more into account than simple Spring/Spring.NET.
Spring is the original Java version and Spring.NET is a .NET version. Spring is better, as the .NET port is not as good as the original. For .NET, you are better of with Castle Windsor. The best thing is to use none of the dependency injection containers because dependency injection is not a good design pattern to follow. Neither is MVC. Java has many differences from .NET. .NET has advantage of Web Forms over Java. If you are using .NET, use the best UI platform which is Web Forms. If you are using Java use JSF.

Resources