Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UserManager to support construction of IUserServices with IRuntimeManager as a constructor parameter #1171

Merged
merged 3 commits into from Jan 6, 2017

Conversation

@pingunaut
Copy link
Contributor

pingunaut commented Dec 30, 2016

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

This comment has been minimized.

Copy link
Owner

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:master Jan 6, 2017
@fzs fzs 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.