Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2455

TransactionScope like implementation for IClientSessionHandle

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API, Session Management
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Current SessionApi is simple, but not fit to developer requirements.

      When i need use session across many repositories - it need to pass IClientSessionHandle to each repository method. But repository interface is domain contract and we need some ambient implementation.

      This api must be optional without any incomatibility to other driver api

      Example:

       

      public interface IUserRepository
      {
         Task<User> Create(IClientSessionHandle sessionHandle, User user);
      }
      public interface IRolesRepository
      {
         Task AssignRoles(IClientSessionHandle sessionHandle, string login, List<Roles> roles);
       }
      

       

       It is not usefull and clear

      We want to see something like this:

       

      public interface IUserRepository
      {
         Task<User> Create(User user); //clear
      }
      public interface IRolesRepository
      {
          Task AssignRoles(string login, List<Roles> roles); //clear
       }
      public class AccountService : IAccountService
      {
            private readonly IUserRepository _userRepository;
            private readonly IRolesRepository _rolesRepository;
       
             private readonly ISessionFactory _sessionFactory;
      
              public AccountService(IUserRepository userRepository, IRolesRepository rolesRepository, ISessionFactory sessionFactory)
             {
           _userRepository = userRepository;
              _rolesRepository = rolesRepository;
      
           _sessionFactory = sessionFactory;
       }
      
       public async Task CreateUser(UserModel user)
       {
             using (_sessionFactory.Create()) //session factory can contain our abstraction
             {
               //operation auto join to current session like TransactionScope in ADO.NET
               await _userRepository.Create(user);
               await _rolesRepository.AssignRoles(user.login, roles);
              }
        }
      }
      

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            zoxexivo@gmail.com Ivan Artemov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: