Getting dependencies in base abstract business layer

Notice: This thread is very old.
dkorpar
Member | 132
+
0
-

I have structure where presenter/components can only access business object and business object is working with different services/repositories etc… I have few services like db connection, queue that should be available in every business object so they're in BaseLogic object from which every other business object is inherited. Is there some way to autowire those services there? I really don't want that presenter has any access to to those services and I don't want to have it in constructor and require them in every business layer. There's few possibilities that I see

  1. using inject* method and set for every business object inject: yes in neon files (would be cool if there's some setting for all services, but there's not)
  2. get those in presenters in inject* method and setting then to business layer object without setting them to any property in presenter.

I would have to make sure business object is created before all inject methods are runned.

@inject annotation is not option since property has to be public and that's a no.

Any suggestions?

Last edited by dkorpar (2017-01-17 11:55)

David Matějka
Moderator | 6445
+
+2
-

would be cool if there's some setting for all services, but there's not

actually, there is :) it's called “decorator”, just add to your config.neon sth like this:

decorator:
	MyBaseClass:
		inject: true

and it will enable inject for all services which extend MyBaseClass

dkorpar
Member | 132
+
0
-

Thanks, this works!
Would be nice if English documentation is up to date and that there's actually all stuffs like that, currently it's not that simple for non Czech speakers to use nette…

Jan Tvrdík
Nette guru | 2595
+
+2
-

@dkorpar This is also sort-of relevant http://www.tomasvotruba.cz/…re-in-nette/

dkorpar
Member | 132
+
0
-

@JanTvrdík This is excellent, great source, thanks, any other blogs for nette on English?