cancel
Showing results for 
Search instead for 
Did you mean: 

Getting a singleton Component (from usage)

Former Member
0 Kudos

Dear Developers,

I am developping a multicomponent application. I have a model component which is the model of my MVC and is created from my main component.

I have other components which are loaded dynamically at runtime and which also define a usage to this model component.

The use of my model component is only relevant to the application if this component is a singleton in my work process.

Is there a builtin way to get a list of instances of a component usage within my work process?

How can I share "component instances" (of a usage which points to the same class or interface) between components ? Which would be the best way or the WD4A way ?

Sincerely,

Olivier MATT

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi again.

Another way would be to inject the model class to all other components via a set method in the component interface.

So the main component would initially create the model and pass it to all other components via their interface controllers.

Cheers,

Sascha

Former Member
0 Kudos

Hi Sascha,

My original idea was to use a normal ABAP class with the singleton DP.

But I have seen people writing model components and using special magic with the USAGE_MODEL definition which seems to have its own way to be dealt with.

I had a look into IF_WD_COMPONENT_USAGE~CREATE_COMPONENT method then I see MODEL_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE OPTIONAL.

What is the use of this ? What is the WD4A way to deal with models ?

Could the architect or developers of the framework enlighthen us ? .. or you Sascha if you know it

Best regards,

Olivier Matt

Former Member
0 Kudos

Hi Olivier.

This is another way to transfer the reference of the usage to a used component.

If you define a component usage of the type of your model_component in the target component (which should use the same reference) and you name this usage MODEL_USAGE you can transfer your model component usage via the create_component method.

Example:

data:
        lr_model_comp_usage    type ref to if_wd_component_usage,
        lr_modeluser_comp        type ref to if_wd_comp_usage.

lr_model_comp_usage = wd_this->wd_cpuse_usage_modelcomp( ).
if lr_model_comp_usage->has_active_component( ) is initial.
   lr_model_comp_usage->create_component( ).
endif.

lr_modeluser_comp = wd_this->wd_cpuse_usage_modelusercomp( ).
if lr_modeluser_comp->has_active_component( ) is initial.
   lr_modeluser_comp->create_component( model_usage = lr_model_comp_usage ).
endif.

Cheers,

Sascha

Former Member
0 Kudos

Hi again,

just have a look on Regina's and Thomas's statement in this thread:

https://forums.sdn.sap.com/click.jspa?searchID=3159927&messageID=2666391

Cheers,

Sascha

Message was edited by:

Sascha Dingeldey

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Olivier.

It is possible to pass the reference of the usage from your main component which controlls everything to all

other components that have a usage to the same component.

So all your components should have a set_usage method which takes the

reference to the usage. Your main component then can call this method and pass

the reference.

In the implementation of this method in all other components do the following:


data:
        lr_usage    type if_wd_component_usage.

lr_usage = wd_this->cpuse_usage_name_of_usage( ).
lr_usage->enter_referencing_mode( lr_usage_refrence_from_main_component ).

But I would recommend not to use compoents as model. Just create a normal

class or set of classes which reflects your model and build it as singleton. Then

you can access it from each component. Guess this is easier.

Cheers,

Sascha

Message was edited by:

Sascha Dingeldey