[erlang-questions] separating application from gen server
Ludovic Coquelle
lcoquelle@REDACTED
Wed Nov 28 14:14:27 CET 2007
Usually I let the application get the config variables, and start the
gen_server with the good params. So that only application manage its config
(through a dedicated module, such that it is easy to move the config from
env to DB or other file ... I did need to parse a ini file once :( ).
Something in the line of:
myapp.erl:
start() ->
ThingCfg = config:server_of_things(),
thingserver:start_link(ThingCfg).
config.erl:
server_of_things() ->
{ok, Cfg} = application:get_value(things_key),
Cfg.
thingserver.erl:
start_link(Args) ->
gen_server:start_link({local,?MODULE},?MODULE,Args,[]).
On 11/28/07, Ulf Wiger (TN/EAB) <ulf.wiger@REDACTED> wrote:
>
> Tom Whitcomb skrev:
> > Hi,
> >
> > I want to use application:get_env in my gen_server but it feels wrong
> > to create a dependency between my gen_server and a specific application.
> >
> > Is there a recommended way for a gen_server to receive and reference
> > the application that contains it?
>
> application:get_application() -> {ok, AppName} | undefined
>
> will return the name of the application which contains
> the current process.
>
> application:get_env(Par) -> {ok, Val} | undefined
>
> will get the environment variable Par from the current
> application. get_env(AppName, Par) will get it from the
> specified application.
>
>
> BR,
> Ulf W
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071128/26f39a9c/attachment.htm>
More information about the erlang-questions
mailing list