Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Limit [FromServices] to apply only to parameters #3507

Closed
Eilon opened this issue Nov 10, 2015 · 4 comments
Closed

Limit [FromServices] to apply only to parameters #3507

Eilon opened this issue Nov 10, 2015 · 4 comments
Assignees
Milestone

Comments

@Eilon
Copy link
Member

Eilon commented Nov 10, 2015

This should help reduce a lot of the confusion around this feature.

It currently applies to parameters and properties. The problem with properties is that it appears to many people that it can be applied to any property of any object. But in reality it works only with properties on objects that are model bound, which is controller properties, and sub-properties of types used in MVC action method parameters.

By limiting [FromServices] to only parameters, that will restrict the usage to one that will always work: top-level action method parameters.

cc @rynowak

@rynowak
Copy link
Member

rynowak commented Nov 10, 2015

The problem with properties is that it appears to many people that it can be applied to any property of any object.

Agreed, we've had a number of issues posted by users with confusion around how this feature should be used. There's really been a fairly large amount of feedback both of the kinds "[FromServices] is weird and I don't like it" and "[FromServices] has confounded me". It feels like a trap, and something that the team would still be answering questions about years from now.

We feel like most valuable scenario for [FromServices] is on method parameter to an action for a service that you only need in that one place.

/cc @danroth27 - docs changes

To anyone in love with the current [FromServices], I'd strongly recommend looking into a DI system that can do property injection (Autofac, for example).

@Eilon Eilon added this to the 6.0.0-rc2 milestone Nov 12, 2015
@Eilon
Copy link
Member Author

Eilon commented Nov 12, 2015

@pranavkm please sync with @rynowak on what kind of sample we might want for this to show the current behavior.

@Eilon
Copy link
Member Author

Eilon commented Nov 18, 2015

@pranavkm Done?

@Bartmax
Copy link

Bartmax commented Nov 18, 2015

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants