Issue #283 resolved

How to override default binding in a custom plugin

Anonymous created an issue

Hi,

I search to override the DefaultGroupManager to MyCustomGroupManager but I have an exception :

1) A binding to sonia.scm.group.GroupManager was already configured at sonia.scm.ScmServletModule.bind

My code is :

extension public class MyServletModule extends ServletModule {

@Override
protected void configureServlets() {

bind(GroupManager.class).to(MyCustomGroupManager.class);

}

}

Thanks

Comments (10)

  1. yop190

    Thanks that's work fine ;)

    But, have you plan to move DefaultGroupManager and DefaultUserManager to the core ? (For now I have duplicate file and I don't like this ...)

    In fact I want to extend the search feature when you use Crowd (merge the result search with local group and with crowd remote group) .

  2. Sebastian Sdorra repo owner

    Ok, i've now created a decorator api for the UserManager, GroupManager and RepositoryManager. The new api is available in the latest snapshot of version 1.23 of scm-manager. So be sure your pom uses the 1.23-SNAPSHOT version as parent.

    Here a short example to override the search method of the GroupManager:

    public class ExampleGroupManagerDecorator extends GroupManagerDecorator {
    
      public ExampleGroupManagerDecorator(GroupManager groupManager){
        super(groupManager);
      }
    
      @Override
      public Collection<Group> search(SearchRequest searchRequest){
        Collection<Group> groups = super.search(searchRequest);
        groups.add(new Group("example", "example-group"));
        return groups;
      }
    }
    

    To register your group manager decorator you have to create a GroupManagerDecoratorFactory with a Extension annotation. E.g.:

    @Extension
    public class ExampleGroupManagerDecoratorFactory implements GroupManagerDecoratorFactory {
    
      @Override
      public GroupManager createDecorator(GroupManager groupManager)
      {
        return new ExampleGroupManagerDecorator(groupManager);
      }
    }
    

    Could you please test this new api?

  3. yop190

    Thanks, Sebastian,

    Your code is very clean, I have written my code in few time. I'm going to propose my code to Stephan github repo.

    Let me know if you move these classes to the core, I'll update my code in this case.

  4. Log in to comment