This question already has answers here:
How to create dependency injection for ASP.NET MVC 5?
(9 answers)
Closed 9 months ago.
I have a Blazor application that I am using. The dependency injection works well in the components/pages. But how can I access a dependency from one of my API Controllers?
As your controllers are already injected you only need add a constructor with parameters. The parameters will be injected assuming they are provided.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
We're planning to build a web service to retrieve and send data to an external application.
Someone suggested we use the ASP.NET MVC project. Thing is, we won't have a view. All we're doing is a query and returning the output to the caller. I questioned the use of this project.
He responded that you don't need a view to utilize a MVC project. He added that we can take advantage of the URL routing feature. However, I'm still skeptical.
Is there any reason to choose ASP.NET MVC over a Web API considering we won't utilize the View?
You aren't required to use views (or models for that matter) in MVC. In this case both MVC or Web API would work equally well. There is no advantage of one over the other if you are not using views.
Do note that in ASP.NET Core there is now no difference at all - there is only 1 framework to use and it can be used with or without views.
If you are really want to make some service it's most probably helpful when you use web API. True, it's not necessary to have views in asp.net MVC and also routing is working more similar in both.
The thing is, if you need to authenticate the calls there is little difference how we authenticate calls. Normally web API has come with token-based authentication rather than using cookies use in asp.net MVC.
For your current requirement, the best solution is WebAPI.
You should use MVC controller if you are going return a view. You can return data also from MVC Controller, but is better to user WebAPI controller if you wish to return only data(you can use it like a HTTP service).
The Advantage of using WebAPI is I can say it is a light weight. Hence you can go with WebAPI
This question already has answers here:
ASP.NET MVC 5 error handling
(3 answers)
Closed 6 years ago.
One shouldn't have to wrap every call to the database in a try/catch to accomplish this, should they? Can we just globally log all errors that occur, with one piece of code, vs. writing code to handle each and every possible area where one might occur? If so, how is this accomplished?
edit: I was hoping there was one place in ASP.NET MVC apps where I can place a bit of code to log information from exceptions.
Use ExceptionFilter i.e. HandleError. You can add this filter on controllers. You can log errors through this filter.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have an MVC application and the solution consist of three project as described below:
Store.Domain : Holds the domain entities and logic (repositories created with the Entity Framework).
Store.WebUI : Holds the controllers and views; acts as the UI for the application.
Store.UnitTests : Holds the unit tests for the other two projects.
I will use WebAPI 2 in my application in order to create web services for some of the Android applications. Now I am not sure about the issues below:
1) By keeping in mind security and maintenance concerns, should I create a separate project for WebAPI or use WebAPI in the Store.WebUI project? As I will also install WebAPI documentation nuget and it will create several folders and files in the project, I think creating a new project maybe better.
2) Assuming to create a new project dedicating for WebAPI, what would be the project type and choices for the WebAPI project? Is it true the following selections as indicated on the screenshot?
Project Type: ASP.NET Web Application
Project Template: Just select Web API
Thanks in advance.
WebApi is an alternative Service oriented application from Microsoft just like WCF. But WCF uses SOAP protocol and WebAPI uses HTTP protocol for communication.
So if you are using WEBAPI to provide service for your MVC application you would host that WEB API service seperately and consume its service by MVC application,
If you want them (MVC and WebAPI) to use in the same project, follow this rules from this article.
Hope that helps.
This question already has answers here:
JSF implementations and component libraries [closed]
(2 answers)
Closed 7 years ago.
During an interview, i had this question :
why still using richfaces or primefaces with jsf 2.0? jsf 2.0 has the ajax capabilities, so what is the advantage of those frameworks vs jsf 2.x ?
Primefaces is a framework on top of JSF-2, and provides components with functionality that would take a big effort to implement in "raw" jsf-2. Look for example at lazy-loading functionality of
p:dataTable
As with any framework, as long as your application can be adapted to the functionality/components provided, you will gain speed in the development.
The drawbacks is of course you have to learn the framework and if the components available doesn't fit your use case, you have to fallback to "raw"-jsf or perhaps even servlets.
JSF is a framework on top of Servlets technology.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What's the difference between WCF Web API and ASP.NET Web API
I've started looking at the new features of MVC 4. One of the notable new features is ApiControllers.
I still cannot understand why to use this rather than WCF WebAPI? Is that because Microsoft's trying to fadeout WCF WebAPI, or gather all tool sets in a single place which is an MVC 4 project?
Please take a look at this.