Cornices / cornice

Build Web Services with Pyramid.
https://cornice.readthedocs.io
Other
384 stars 149 forks source link

@resource/@service decorated class as factory **autowired** or not **autowired**? #496

Open wrkhenddher opened 6 years ago

wrkhenddher commented 6 years ago

Hello all,

Months ago (July 2017), there was a quick discussion about the autowiring factory feature incorporated by me in https://github.com/Cornices/cornice/pull/456

@joesteeve, @joshuaimmanuel, @leplatrem, I (@wjehenddher)

https://github.com/Cornices/cornice/pull/456#issuecomment-403867957 https://github.com/Cornices/cornice/pull/456#issuecomment-407356586 https://github.com/Cornices/cornice/pull/456#issuecomment-407367883 https://github.com/Cornices/cornice/pull/456#issuecomment-407398491 https://github.com/Cornices/cornice/pull/456#issuecomment-407403978 https://github.com/Cornices/cornice/pull/456#issuecomment-407758314 https://github.com/Cornices/cornice/pull/456#issuecomment-460408671

There was no consensus but few alternatives were brought up:

  1. Remove the autowire (basically revert #456)

  2. Add a view config parameter to opt-in/opt-out autowiring the @resource/@service class as the root factory.

  3. Introduce a configuration that can globally enable/disable the autowiring feature. People who want it could enable it.

More Opinions?

More people have chimed in: @grant-humphries

leplatrem commented 6 years ago

I will follow the masses here :)

If 1. is really bad, then revert. Otherwise introduce option (2.)

joesteeve commented 5 years ago

Sorry for the late reply.

There is another option. We could introduce a configuration that can globally enable/disable the autowiring feature. People who want it could enable it.

wrkhenddher commented 5 years ago

We could introduce a configuration that can globally enable/disable the autowiring feature. People who want it could enable it.

Adding to the possible options.

grant-humphries commented 5 years ago

There is another option. We could introduce a configuration that can globally enable/disable the autowiring feature. People who want it could enable it.

+1 for this ^, below are my comments on the topic from #456 (porting them here since this ticket has been designated as the place for further discussion):

...I am having similar issues to those raised in this thread as I am upgrading from version 1.0.0 to 3.5.1. We have have a bunch of existing services that are expecting the Pyramid root factory to be used as the factory for cornice resources when no factory parameter is passed to the decorator.

It seems like too much time has passed for reverting these changes to be an option, but I'm just looking for something to be present in the API that either allows me to set a default factory for all resources or a setting that indicates that the Pyramid root factory should be the default factory for all resources.