in which layer should i implement viewmodel to domain model mapping in Onion architecture? - onion-architecture

Hi I am new to the onion architecture. I have 3 projects in solution, 2 class libraries and an MVC web application.
Core: which have repository interfaces,domain models and business logic.
[core has no dependency]
Infrastructure: which have DBContext, Repository classes.
i am injecting dependency using Unity in controller of web app.
Please suggest where should i put ViewModel to DomainModel Mapping? should i create a new layer? what are the best practices and project architecture for onion architecture?

I would do the mapping in your MVC project. View models are a UI concern so you already have a place to do this.
I would suggest reading the Putting Your Controllers On A Diet series of articles by Jimmy Bogard as a starting point for some good practices:
https://lostechies.com/jimmybogard/2013/10/29/put-your-controllers-on-a-diet-gets-and-queries/

Related

Approach for using AutoMapper in Business Layer .net core 2.1

I have 2 layers in my Application . A API .net core 2.1 and business layer which is a .net core class library .I want to place the automapper profiles in the business layer so that all the mappings are made in the business layer.
I have included the services.AddAutoMapper(); in the startup.cs of API project and placed the profiles in the Business layer. I have referred my business layer in my API layer. The profiles are getting loaded properly but the downside of this approach is, business layer now has dependency on AutoMapper
Is there any other way to achieve automapping in multiple projects.

Using ASP.NET WebApi with a 3 Tier Architecture

I have been trying to get to grips with the use of ASP. NET WebApi recently, I’ve watched a bunch of tutorials and read quite a bit material, but not finding the information I need. This maybe a very basic question, but my idea is to host my webapi with IIS and was aiming for a 3 tier Architecture, something like, Presentation Tier , Business Log and Data Access.
Now I create an MVC 4 project for my presentation tier. But what I am not understanding very well is do I then create another MVC 4 project with a web api template for my business logic and strip out all the controllers, views etc?
Hope I’m making sense.
Thanks for reading.
Whether you should host the WebAPI in a separate ASP.NET application than your MVC project is debatable. Both approaches are correct. For example if you don't want to expose the WebAPI to the public you could host it in some internal network that is accessible only by your MVC application. If you want to expose it to the public then you could host it alongside with your MVC application. So it would really depend whether you want to expose an HTTP API to the public or not.
3 tier architecture doesn't mean (in the general case) SOA (Service Oriented Architecture). If you really need SOA - it's better to have separate projects for API project (Service) and Web UI (Presentation). But if you just need SOA and you don't need REST services (for public access) then it maybe will better to use WCF instead of WebAPI.
Marcel, your MVC is pattern in order to define your presentation tiers, you can also use WebForms, but you have selected MVC,
You must also create Business Layer and DataAccess Layer. these tiers are independent of MVC.
Select MVC just permit you to facilitate unit test (Controller) , facilitate future changing on view's technology, separate businness logic from presentation ...

View part of Spring MVC

I am reading the Developing a Spring Framework MVC application step-by-step specifically the Create the View section.
It uses hello.jsp.
I am new with this. I assume that we can use the View part any client framework like GWT, jQueryUI, etc. without using JSP.
Correct?
Thanks in advance for your help.
Spring integrates with several view technologies out of the box, and it's built to be extensible. Check out "Resolving views with the ViewResolver interface" for an overview and list of common view implementations. To use some view technology, you have to have a ViewResolver implementation for it.

Is there any good sample application to demonstrate how to setup and configure an IoC container with ASP.NET?

I have an asp.net application and have used MVP pattern and created interfaces for all classes to make them testable and apply dependency injection.
I am going to use an IoC container, perhaps Microsoft Unity, to inject the dependencies in a single place.
I've used Spring.NET for a Windows Service application before but for ASP.NET it would be different as we have requests and responses and application life cycle so not sure how to set up it.
Is there any good sample application to demonstrate how to setup and configure an IoC container with ASP.NET?
Many thanks,
If you are looking for a good IOC container - check out http://ninject.org/
There is a decent MVP example on codeplex using Ninject - http://webformsmvpcontrib.codeplex.com/wikipage?title=Ninject
And here is a good example on Stackoverflow using Ninject and the MVP pattern -
ASP.NET MVP Injecting Service Dependency
Windsor has always been my favorite and stackoverflow is the best source

Spring MVC or WebFlow for this project

I have to create an application with
Flex 4 with Swiz (MVC Framework) as the UI Layer,
Spring (MVC or Web Flow) as the Business Layer,
Oracle 10g as Data layer,
Hibernate as ORM which will work with Oracle,
with Maven, with IBM Websphere and Tomcat.
I am trying to decide should I use Spring MVC (since it has to work with Swiz and Flex 4 which is MVC) or should I work with Spring Web Flow. Also any good examples on web with tutorials on this technology set.
I appreciate any help.
Thank you,
Sid
Given that WebFlow is primarily a page-flow framework, it's almost certainly inappropriate for your situation. Your Flex client will likely communicate via AJAX-style calls to the backend, and Spring MVC is the best choice for that.

Resources