Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Trying to improve my design decisions and would like some assistance on the following;

1. Create a service layer that completes Insert/Update/Delete on a SAP system. Using Unity in my VM to resolve the service. - Done
2. I need a verification layer that first runs a simulation. This is simple done by sending/setting in a RFC parameter IsCommit. This layer will also log any issues that is raised by SAP.

So I dont want to duplicate the code for this layer. But want this layer to run the same code but only add the new RFC Parameter. It will also log any issues raised through the simulation. Any suggestions on my approach? Something like a generic service that resolves the service/ method, sets the IsCommit paramater and then executes the base service?

VM

C#
public static BankAccountVM Save(BankAccountVM bankVM)
        {
            var svc = GlobalContext.Current.Container.Resolve<IBankService>();
            BankAccount bankAccount = bankVM.GetModel();

            svc.Update(bankAccount);
            return bankVM;
        }


Service Layer
C#
public class BankService : BaseService, IBankService
{
    private readonly Common _common;
    private readonly IUnityContainer _container;
    private readonly LookupTextValues _textHelp;

    public bool IsCommit { get; set; }

    public void Update(BankAccount bankAccount)
    {
          //Breakdown bank account into rfc paramters

          if(IsCommit )
          {
               //add IsCommit RFC parameter
          }
    }
}


Verification service?
Posted

1 solution

Create override with extra parameter. In the version without parameter, call the one with parameter, just set it to some default (as you need).
Example:

C#
Update (BankAccount ba) {
    Update (ba, false);
}

Update(BankAccount ba, boolean isCommit)



If this helps please take time to accept the solution. Thank you
 
Share this answer
 
Comments
Member 10853319 17-Dec-14 16:22pm    
Thanks Sinisa,

Appreciate the answer. This was one of my options, but decided against it as the verification layer is only going to be made available for the SAP services. So wanted to keep the common services clean for other providers. I have additional logging requirements on this verification layer as well. Was possibly thinking along the lines of a decorator pattern?
Sinisa Hajnal 18-Dec-14 2:17am    
Decorator is hard to do on a service class. And if you do it as BankAccount decorator, it would still require decorator of your bank account to have access to the function in question which again would mean access to the service. Why not just give bank account method Save with IsCommon parameter which will be set or not as you need it.

Finally, decorator would have more sense if you have number of related classes that need some functionality extension, but you have single class with single method. Just add it to the class and you're done.
Member 10853319 18-Dec-14 19:16pm    
Thanks Sinisa, I have quite a few services that I am implementing for a SAP provider. Hence the question. I dont want to have to implement a parameter for each of the services, then a new service provider would also have to implement this parameter with no meaning. Hope this makes sense..
Sinisa Hajnal 19-Dec-14 2:11am    
Then you already have a solution. Add Save method to the class (BankAccount), set the property on the service and you're done. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900