#1 2017-06-27 14:50:59

jaclas
Member
Registered: 2014-09-12
Posts: 215

One service under two names

I have a interface based service:

ISomeService

Customers use this service, but now I would like to change it's name to ISuperSomeService, and for a moment provide the same service under two names, and in the future, the older interface will be removed.

Is it possible to do this without cloning the interface and class and without registering two, separated services? Some mapping or server routing?

Offline

#2 2017-06-27 20:33:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: One service under two names

No, here mapping is by convention by default, so by default you need to specify a new interface type (with its own GUID) to have diverse URI routing.
This should cover most of the use cases, in practice.

BUT you can define you own routing class, which is some work, but is possible.
See https://synopse.info/files/html/Synopse … #TITLE_447

Offline

#3 2017-06-27 21:15:23

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: One service under two names

I create this code:

type
  TssRestRoutingREST = class(TSQLRestRoutingREST)
  protected
    function URIDecodeREST(): boolean; override;
  public
  end;


implementation


function TssRestRoutingREST.URIDecodeREST(): boolean;
var
  l: Integer;
begin
  Result := inherited URIDecodeREST;
  l := Pos('SomeService', URI);
  if l > 0 then
  begin
    URI := StringReplace(URI, 'SomeService', 'SuperSomeService', [rfReplaceAll]);
    URIWithoutSignature := StringReplace(URIWithoutSignature, 'SomeService', 'SuperSomeService', [rfReplaceAll]);
  end;
end;

and it works well, but is it the best method? What can be the side effects?

Offline

#4 2017-06-28 06:54:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: One service under two names

StringReplace() is not a good way of changing routing, since it may replace some content within inlined parameters, for instance.
So exact parsing may be a better idea.

Note also that you should better use StringReplaceAll() from SynCommons.pas, which is faster and works directly with RawUTF8 content, whereas StringReplace() induces a conversion to string.

Offline

#5 2017-06-28 10:49:01

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: One service under two names

I know about conversions and other issues, this is simple code to test solution.
Thanks for support!

Offline

Board footer

Powered by FluxBB