Paul Sandoz wrote:
> Bertold Kolics wrote:
>> Paul Sandoz wrote:
>>> Bertold Kolics wrote:
>>>> My case maybe special, because I have a constructor in my
>>>> injectable provider that takes some parameters. The simplest way I
>>>> can find to setup an LW HTTP Server was something like this (hacked
>>>> together from the ContainerFactory and HttpServerFactory classes).
>>>> Is there a better way?
>>>>
>>>
>>> We need to create a better way. What if there was a specific
>>> resource config property that contains a list of injectable provider
>>> instances to add to the web application?
>>>
>>> I can modify the ContainerFactory to check for this property.
>> Sounds good to me as long as there is not much restriction on the
>> constructor of the injectable provider.
>>
>
> I have managed to improve things and make it more general. Since
> instances of InjectableProvider are providers the
> WebApplication.addInjectable method was really just a special case of
> adding an instance of any provider. So i have removed that method.
>
> In the latest source/build you can achieve what you require as follows:
>
> ResourceConfig rc = ....
> rc.getProviderInstances().add(new MyInjectableProvider(myParams));
>
Thank you. That helps a lot. It reduces the complexity considerably.
This is how it looks for me now:
final PackagesResourceConfig config = new PackagesResourceConfig(
new String[] {"com.example.api.rs" }
);
config.getProviderInstances().add(
new ServerAnnotationInjectableProvider(eidm)
);
final HttpHandler handler =
ContainerFactory.createContainer(HttpHandler.class, config);
final HttpServer server =
HttpServerFactory.create("
http://localhost:9998/", handler);
Bertold
PS: the PackagesResourceConfig constructor javadoc should make it
obvious that the resource will be looked up in the provided packages *as
well as* any packages below those specified.