PAK Core – IServiceProviderFactory
What you will learn
In this short summary you will get an idea how to use a factory to create an
Before giving a short example on how the interface should be used, this section describes the signature of the
IServiceProviderFactory interface, as well as an overview on which methods have to be implemented.
Creates a new instance of an
This section briefly outlines a few examples demonstrating how the implementing
IServiceProviderFactory should be used.
Suppose that we have written an
IServiceProvider which only allows to register services at construction time. Of course you could use the constructor directly like shown in the usages here or you can pull the registration of services away from configuring the provider to use. The example below shows you a possible way to use the factory interface.
...; final ContextBuilder cb = new ContextBuilder(); (1) // Setting up factory final SimpleServiceProviderFactory factory = new SimpleServiceProviderFactory(); factory.addService(IPersistenceService.class,new SimplePersistenceService()); (2) factory.addService(IMappingService.class, new MappingService()); (2) // Finishing engine builder cb.setServiceProviderFactory(factory); (3) final IContext context = cb.build(); final IEngine engine = new EngineBuilder()...setContext(context).build(); ...;
|2||We register two services to the factory which will be given to the
|3||We give the
IContext will contain the
IServiceProvider created by the factory with all the services preregistered already.
de.asap.pak.core.simple.context.SimpleServiceProviderFactory: Prototype implementation of the interface, which returns the
SimpleServiceProvider. Allows to preregister services in a map which is given to the provider at construction time.
de.asap.pak.extra.guice.GuiceServiceProviderFactory: Creates a
GuiceServiceProviderwhich uses the functionalities of guice to register services. Allows registering whole guice modules before provider creation.