Skip to content

Conversation

martinspielmann
Copy link
Contributor

In gitblit-crowd-plugin I make use of my own subclass of ConfigUserService.
Unfortunatelly i'm not able to get the data directory from the settings during construction, which is quite bad.

A very simple approach of supporting customized IUserServices is implemented in this PR:
Behavior at the moment:

  • Try to instantiate an IUserService with default constructor.
  • If class not found ->create ConfigUserService from conf file
  • If instantiation fails -> log error (and die... this will cause NullPointerExceptions afterwards

Newly implemented behavior:

  • Try to instantiate an IUserService with default constructor.
  • If class not found -> create ConfigUserService from conf file
  • If instantiation with default constructor fails -> Try again with constructor having IRuntimeManager as a parameter
  • If this instantiation fails also -> log error (and die... this will cause NullPointerExceptions afterwards

This way no further changes in existing UserServices are needed. New implementations will have the possibility to access all application settings by implementing a constructor like the following:

public class MyCoolUserService implements IUserService {
  public MyCoolUserService(IRuntimeManager manager){
    //do whatever you like. you know the runtimeManager now
  }
}

@gitblit
Copy link
Collaborator

gitblit commented Jan 5, 2017

I like this idea. Would you please make instantiation of a user service a new method? i.e. extract realmClass.newInstance() and your catch block into a new method.

@gitblit gitblit merged commit 5541f37 into gitblit-org:master Jan 6, 2017
@flaix flaix modified the milestone: 1.9.0 Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants