How to work with .net 6 web api , where shared business logic across multiple apis/contorllers?

59 Views Asked by At

I am beginner in Web Development. I need a help designing .net 6 web api project.

I have web application , which has front end with HTML-JS-CSS and back end with .net 6 web api.

I have set of services

  1. login API
  2. Pre_Processing Api
  3. Transfer API

I have added session in project.

front end calls "pre_processing api", after which it return large set of objects to front end. For each such object the third "transfer api" is been called.

I have injected dbcontext using entity framework.

Now I need to add credit mechanism for allowing and disallowing transferring activity which is based on platform basis (having multiple users on one system).

The business logic is shared in "pre_processing" and "transfer api". I need to lock/deduct a credit value from database table for user , on how many transfers he is going to make in advance. which should reflect to other user.

If I lock/deduct credit in database table in pre_processing(controller) api. I need to rollback the locking of credits [the action of pre_processing api] on results(success /failure) of "transfer api".

storing everything information in session variable is making logic complex and inaccurate.

How could i go further?

I am not able to inject a dbcontext per user session?. Is there any library one can use to implement credit based transactions?**

I tried with storing transaction information in session. The dbcontext now disposes with each http request. But i am expecting more robust and consistent approach to solve this problem.

0

There are 0 best solutions below