In which layer would you implement transactions using asp.NET TransactionScope? - asp.net

I have a service, business and data access layer. In which layer should I implement transactions using asp.NET transactionscope? Also, is nesting Transactions a good thing because I had problems with that?

Transaction Scope is part of .net not specific to asp.net
We would place the tansaction scope in the business layer. The service layer is more of a facade. If something requires a transaction it should be within a single business operation.

Related

(asp.net core mvc) How can I use identityUser in UI layer with product in entity layer

I've used Identity package in WebUI layer. I want to associate these users with the product that I keep in the entity layer.
Checkout below diagram image
I cannot reference the Identity user class. How can I do that?
I am getting this below error.
Thanks
It seems that you are using the Traditional "N-Layer" architecture. Using this architecture, users make requests through the UI layer, which interacts only with the BLL (Business Logic Layer). The BLL, in turn, can call the DAL (Data Access Layer) for data access requests. The UI layer shouldn't make any requests to the DAL directly, nor should it interact with persistence directly through other means. Likewise, the BLL should only interact with persistence by going through the DAL. In this way, each layer has its own well-known responsibility.
Normally, the DAL and BLL application are class library, when we use it, we could add the project reference (find the build .dll file).
I want to associate these users with the product that I keep in the
entity layer. I cannot reference the Identity user class. How can I do
that?
So, about this issue, you could try to put the Identity User class in the DAL layer and configure relationship with other model, then add reference in the BLL layer or the UI layer.
More detail information about Common web application architectures, check the following articles:
Common web application architectures
N-Tier Architecture in ASP.NET Core
N-Tier Architecture and Tips
You could add a Data Access Layer for your Identity DbContext: Tutorial video
The Business layer can reference the Identity Data Access Layer. The BLL can take care of finding users and finding Products(I'm guess are stored in Adt.DataAccess layer). If you need to do processing of AspNetUsers table against Products table, you can always combine the results of querying both Data Access Layers in memory in the BLL.

SOA Publishing Messages vs Calling Procedures

The project I am working on is moving from an n-tier to a SOA architecture so I have been reading up on good SOA practices. I'm struggling to understand the dynamic between avoiding RPC style services in favor of event driven services, and the requirement of User Interfaces to retrieve data and do it speedily.
So for instance, ideally a SOA architecture would be composed of repeatable business process wherein you could simply publish a message onto an ESB which would handle finding the services that handle that message. So rather than executing a procedure called "Setup New User" which set out to do all the tasks related to new user setup, you would publish a message into the ESB that just contained the new user's details and had the appropriate document type "New User" and then the ESB would find services that handled that event that would then do whatever domain specific new user provisioning was required.
However, sometimes you just need data. Maybe you have a page that shows some list of user associated data. You can't just fire off a message into the ESB because you need data back and you need it now. Also, you aren't really triggering any business processes; you're just retrieving data from previously invoked business processes (the processes that caused the user to be associated with the data for instance). So to give a concrete example, maybe I just want to see the list of 10 Netflix movies a user has watched recently.
How do you reconcile these disparate types of services in a single SOA system?
In an ESB, where event-driven approach is followed, you have all kinds of listeners, that detect events and act accordingly. These listeners may wait for the appearance of direct messages via some protocol at certain endpoint for example. No matter what the trigger is - a purely business event that starts a business process or a technical call that just needs to retrieve some data, it is still an event that is handled by the ESB. So you are not technically breaking the event-driven approach - it is enforced by your ESB solution. Moreover keep in mind SOA doesn't impose such limitation - you do not have to implement everything in event driven manner.
In your case (provided, you don't have a dedicated BPM solution in place), I'd identify and implement two kinds of services on two purely conceptual layers in the ESB:
Technical services (the event is an incoming direct message for retrieval/modification of data), that can be either called directly by another system (via the ESB) or called by other process services.
Process services on the top (business) layer that are being triggered in a event-driven way (using topic queue for example, where process services listen for their triggering event)
However, this may not be the most optimal approach. I've been discussing business processes in a dedicated business process layer versus process services in the ESB in this topic. Feel free to check it out, because it is kind of related with your question.

WCF Data Service or just WCF Service?

I am trying to decide which way to go. I have a solution that needs to have a web service and a client side which is a windows phone 7 project. the WP7 project needs to communicate with the database through the WCF service.
I am a little bit confused as to which way i should choose to go, and what are the differences, advantages/disadvantages of regular WCF service file VS the WCF Data Service.
Which way will be easier to go with considering my wp7 app needs to run queries on some tables on the database, nothing too fancy.
Any explanation will be welcomed.
Thanks
WCF Data Services are great if you need CRUD and flexible query capabilities - they allow you to expose underlying data (e.g. via Entity Framework) and control security with a minimum of development effort, as a RESTful API, especially to AJAX and SPA type client front ends. (Also, note that WebAPI now also offers similar capabilities).
WCF Services are more for Formal "Service" and "Operation" integration capabilities, where there is a lot more business focus, e.g. rules, processing, workflow, etc.
e.g. WCF would be useful to Submit a Claim for Processing (custom / rich graph of data input and output), Trigger a Nightly batch job (void response), etc.
Also, you can combine both technologies, e.g. for a CQRS type architecture, by using Data Services for the Query, and WCF for the Command type capabilities.

Where are web services in three-tier architecture in c#

Where are web services typically found in three-tier architecture? What are some guildines for adding a new layer?
Web services usually, in fact, ARE middle tier. Client calling web services calling a storage (i.e. database) is a general pattern.
Well, if you go by the definition here, the webservice would be between the Business Access Layer and the Presentation Layer. It is simply a transport between the two layers. Your webservice could contain the Business Access logic but I don't think that is good design.
Well it depends, are you using them for Tier communication? are you setting up public facing web services? etc.
If you are using them for Tier communication they exist as inner layers at the tier level.
If you are making a public facing web service(as in out side of the application), then they are at the UI layer, depending on your needs this could be the same project as your UI or it's own.
You start by mixing up layers with tiers; they are not the same. You don't provide any information about your application which makes it impossible for people to answer you anyway.
I strongly recommend you to read some books about enterprise architecture; Fowler is a good author.

In which layer should webservices be consumed?

I am building an ASP.NET 3.5 Web Application which has the three standard layers (DAL,BLL and UI). I have to consume some third party web services and display the information on the UI. In which layer should I consume this web services and can you also point me to some good examples?
As is normally the case in questions like this, "it depends." It depends on what the Web Service is doing for you and whether you need to do anything else with the response when you get it. I'm guessing, however that it's giving you supplementary data to your BLL. In that case some Infrastructure service between your DAL and BLL might be a good place.
It's never a good idea to have your UI layer directly depend on a third-party service. What happens if it changes?
In this kind of situation I've generally regarded the third-party Web service as a similar resource to a SQL database, so I've wrapped it in its own layer which is then called from the business logic.
This makes it possible to map the Web service objects to my own domain objects. It also makes it easy to stub out the Web service for testing, and decouples my business logic from the third-party service.
In many cases its usually in the business or service layer. Usually several different combinations of MVC layers make calls into the service layer, and so the common functionality of a Web service should be found there.

Resources