Jump to content
Stuart Clennett

Adding a second app to a MARS Engine

Recommended Posts

Hi,

 

I've tried adding a second app to my MARS rest engine (in order to support my api's version 2) as follows:

 

class constructor TServerEngine.CreateEngine;
var
  MyApp, MyApp2 : TMARSApplication;
begin
  FEngine := TMARSEngine.Create;
  try
    // Engine configuration
    FEngine.Parameters.LoadFromIniFile;

    // Application configuration
    MyApp := FEngine.AddApplication('IBCSApp', '/ibcs', [ 'Server.Resources.*']);
    // Second Application (version 2 of the API)
    MyApp2 := FEngine.AddApplication('IBCSApp2', '/ibcs2', [ 'server2.Resources.*']);
    // [....]
End;

And I've created a server2.Resources.pas file into which I've added a simple "/healthcheck" resource that returns the server time as a string.  I've also added this line

 

initialization
  TMARSResourceRegistry.Instance.RegisterResource<THealthCheck>;

But when the server runs, IBCSApp2 is shown in the list of engines, but it does not contain the /healthcheck resource. 

 

I should mention that the original app (IBCSApp) also has the same resource name (/healthcheck) implemented by a different class.

 

I guess I am missing something?

 

Thanks

Stuart

 

Edited by Stuart Clennett

Share this post


Link to post

Hi, everything seems fine, just be sure your call to TMARSResourceRegistry.Instantce.RegisterResource<THealthCheck> takes place *before* the second call to AddApplication (in TServerEngine.CreateEngine method).

I usually make this happen adding the name of the unit where THealthCheck to the uses clause list of the Server.Ignition.pas file (in the MARSTemplate demo, you can spot the Server.Resources unit listed there for the same reason).

 

I am considering, in a future version of MARS, to switch from this 'initialization based' way of registering resources to a more 'configuration based' one. Still have to think about it and choose a simple approach to this problem.

 

Sincerely,

Andrea

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×