View Javadoc

1   /*
2    * Copyright (c) 2015 Maxim Yunusov
3    *    Licensed under the Apache License, Version 2.0 (the "License");
4    *    you may not use this file except in compliance with the License.
5    *    You may obtain a copy of the License at
6    *
7    *        http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *    Unless required by applicable law or agreed to in writing, software
10   *    distributed under the License is distributed on an "AS IS" BASIS,
11   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *    See the License for the specific language governing permissions and
13   *    limitations under the License.
14   */
15  
16  package org.maxur.perfmodel.backend;
17  
18  import org.glassfish.hk2.api.InjectionResolver;
19  import org.glassfish.hk2.api.InterceptionService;
20  import org.glassfish.hk2.api.TypeLiteral;
21  import org.glassfish.hk2.utilities.binding.AbstractBinder;
22  import org.glassfish.jersey.server.ResourceConfig;
23  import org.maxur.perfmodel.backend.domain.Project;
24  import org.maxur.perfmodel.backend.domain.Repository;
25  import org.maxur.perfmodel.backend.infrastructure.ProjectRepositoryLevelDbImpl;
26  import org.maxur.perfmodel.backend.rest.RestServiceConfig;
27  import org.maxur.perfmodel.backend.service.*;
28  import org.maxur.perfmodel.backend.service.impl.PropertiesServiceHoconImpl;
29  import org.maxur.perfmodel.backend.service.impl.WebServerGrizzlyImpl;
30  
31  import javax.inject.Named;
32  import javax.inject.Singleton;
33  
34  /**
35   * Application Configurations
36   *
37   * @author myunusov
38   * @version 1.0
39   * @since <pre>01.09.2015</pre>
40   */
41  final class Config extends AbstractBinder {
42  
43      @Override
44      protected void configure() {
45          bind(ConfigurationInjectionResolver.class)
46                  .to(new TypeLiteral<InjectionResolver<Named>>() {
47                  })
48                  .in(Singleton.class);
49          bind(RestServiceConfig.class)
50                  .to(ResourceConfig.class)
51                  .in(Singleton.class);
52          bind(HK2InterceptionService.class)
53                  .to(InterceptionService.class)
54                  .in(Singleton.class);
55          bind(PropertiesServiceHoconImpl.class)
56                  .to(PropertiesService.class)
57                  .in(Singleton.class);
58          bind(WebServerGrizzlyImpl.class)
59                  .to(WebServer.class)
60                  .in(Singleton.class);
61          bindFactory(ApplicationProvider.class)
62                  .to(Application.class)
63                  .in(Singleton.class);
64          bindAsContract(new TypeLiteral<ProjectRepositoryLevelDbImpl>() {
65          }).to(new TypeLiteral<Repository<Project>>() {
66          }).in(Singleton.class);
67  
68          bindFactory(DataSourceProvider.class)
69                  .to(DataSource.class)
70                  .in(Singleton.class);
71          bindFactory(DataSourceProvider.class)
72                  .to(Database.class)
73                  .in(Singleton.class);
74  
75      }
76  }