Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convention based binding in ASP.NET 5 / MVC 6

It is possible to register dependencies manually:

services.AddTransient<IEmailService, EmailService>();
services.AddTransient<ISmsService, SmsService>();

When there are too much dependencies, it becomes difficult to register all dependencies manually.

What is the best way to implement a convention based binding in MVC 6 (beta 7)?

P.S. In previous projects I used Ninject with ninject.extensions.conventions. But I can't find a Ninject adapter for MVC 6.

like image 883
hcp Avatar asked Sep 22 '15 11:09

hcp


People also ask

What is model binding in MVC?

What Is Model Binding? ASP.NET MVC model binding allows mapping HTTP request data with a model. It is the procedure of creating . NET objects using the data sent by the browser in an HTTP request. Model binding is a well-designed bridge between the HTTP request and the C# action methods.

What is model binding in asp net core MVC?

Model binding allows controller actions to work directly with model types (passed in as method arguments), rather than HTTP requests. Mapping between incoming request data and application models is handled by model binders.

What is the use of bind attribute in MVC?

Bind Attribute ASP.NET MVC framework also enables you to specify which properties of a model class you want to bind. The [Bind] attribute will let you specify the exact properties of a model should include or exclude in binding.

What is @model in Cshtml?

The @model directive allows access to the list of movies that the controller passed to the view by using a Model object that's strongly typed. For example, in the Index.cshtml view, the code loops through the movies with a foreach statement over the strongly typed Model object: CSHTML Copy.


1 Answers

No, there is no support for batch registration in the ASP.NET 5 built-in DI library. As a matter of fact, there are many features that are needed to build large SOLID applications, but are not included in the built-in DI library.

The included ASP.NET DI library is primarily meant to extend the ASP.NET system itself. For your application, you are best off using one of the mature DI libraries out there, and keep your configuration separate from the configuration that used to configure the ASP.NET system itself. This removes the need for an adapter.

like image 188
Steven Avatar answered Nov 14 '22 23:11

Steven