Jump to content
Bjørn Larsen

Invoke function in other resource class

Recommended Posts

Hi,   

 

I have a MARS server with multiple resource-classes. In one of these classes I would like to insert data that is provided from a method on another resource class.

Example:

TResourceA = class
  [GET] function GetSubData: String;
end;

TResourceB = class
  [GET] function GetAllData: String;
end;

 

When ResourceB.GetAllData is invoked I would like to include data from ResourceA.GetSubData in the response.

This works fine by creating an object of TResouceA and call GetSubData long as ResourceA does not use objects injected through attributes. (E.g [Context] FD: TMARSFireDAC);

 

What is the correct way to do this when ResourceA uses attributes ([Context] FD: TMARSFireDAC)?

 

Best regards, 

Bjørn Larsen

Share this post


Link to post

Hi, nice question, sorry for the late of my reply.

 

One thing you can do is to have an inheritance hierarchy. TResourceB may inherit from TResourceA.

That way it should be easy to include data from GetSubData in the GetAllData result.

You can still keep two distinct resources and MARS will inject everything on this or that class depending on the matching of the request path.

 

Another way would be to pass the Context-Injected instance from one resource to the other. Through an overloaded method for example. Or through a property.

 

I am going to make the injection mechanism more available to direct use in the future. Stay tuned. 

 

Sincerely,

Andrea

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
×