-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Naming inconsistency between [Activate] and @inject #2151
Comments
I wondered the same thing. And inject makes a lot of sense, but activate? Seems very ambiguous what the intent of that is. |
@rynowak @DamianEdwards @Eilon Do we still plan to move from [Activate] to [FromServices]? |
Personally, I prefer Whatever name is chosen, I really hope it is consistent between Mvc and Razor. Using different names for the same thing increases the concept count unnecessarily (more cognitive load). I'm not sure |
I will grant you that [FromServices] is better than [Activate], but I would still strongly argue for [Inject] or [Injected]. IMO, using "inject" aligns well with Dependency Injection while also expressing more with less confusion than [FromServices]. Both basically tell me that the property will be set by someone/thing else, but [FromServices] feels oddly specific about who/what will inject it - while at the same time "Services" is so ambiguous that it feels confusing. While [Inject]/[Injected] seems much less about how the property will be set and more about the fact that it will be. Just my 2c. |
👍 on |
👍 on [Inject] as well |
I agree, |
👍 on |
👍 for |
FYI More generally the names of some of these concepts and attributes haven't completely solidified. Interesting discussion here... |
I'm not sure what the prevaling philosophy is 'round these parts, but I thought models depending on services is an antipattern. Moreover, am I understanding correctly in thinking that |
We are definitely hearing a lot of feedback about the naming and behavior of First, some guiding principles:
Proposal:
public class MyController
{
[ActionContext]
public ActionContext Context { get; set; }
} |
It's probably okay to restrict the availability of property & method injection to certain scenarios to help guide people. What doesn't make sense is why the system is being designed to discriminate the various types of things it will inject? Ideally it should just be something that the container can resolve. Whether it's a "Service", a "Context" or anything else - really that's immaterial to the act of injecting. Possible counter-proposal:
Ideally the system should be agnostic so that people aren't cornered and so that the API is easier to intuit just by reading the code. public class MyController {
[Inject]
public ActionContext Context { get; set; }
public ActionResult createMyStuff([Inject] MyStuffService stuffService) {
}
} |
I would agree with @atrauzzi. For me as a user it was absolutely unclear why it's needed different approaches for injecting "contexts" and "services". |
This change removes [Activate] from ViewComponents. Accessing context should be done through [ViewComponentContext]. Accessing services should be done though constructor injection.
This change removes [Activate] from ViewComponents. Accessing context should be done through [ViewComponentContext]. Accessing services should be done though constructor injection.
Are the context objects taken from the services container, or from somewhere else? If it's the former, then I agree with @atrauzzi, that a single If it's the latter, then I think that a single attribute would be better. I also prefer Finally, it seems to me that |
This change removes [Activate] support from TagHelpers. TagHelpers which need access to context should use [ViewContext] to have it injected. To access services, use constructor injection.
This change removes [Activate] support from TagHelpers. TagHelpers which need access to context should use [ViewContext] to have it injected. To access services, use constructor injection.
This change completely removes [Activate]. In a controller, you should constructor injection or [FromServices] to access services. To access context items (ActionContext, ActionBindingContext, root ViewDataDictionary) you should use the respected attribute class. We'd like to consider streamlining this further in the future by getting down to a single injectable context for controllers, but for now this will have to do.
This change removes [Activate] from ViewComponents. Accessing context should be done through [ViewComponentContext]. Accessing services should be done though constructor injection.
This change removes [Activate] from ViewComponents. Accessing context should be done through [ViewComponentContext]. Accessing services should be done though constructor injection.
This change removes [Activate] support from TagHelpers. TagHelpers which need access to context should use [ViewContext] to have it injected. To access services, use constructor injection.
This change removes [Activate] support from TagHelpers. TagHelpers which need access to context should use [ViewContext] to have it injected. To access services, use constructor injection.
This change removes [Activate] support from TagHelpers. TagHelpers which need access to context should use [ViewContext] to have it injected. To access services, use constructor injection.
This change completely removes [Activate]. In a controller, you should constructor injection or [FromServices] to access services. To access context items (ActionContext, ActionBindingContext, root ViewDataDictionary) you should use the respected attribute class. We'd like to consider streamlining this further in the future by getting down to a single injectable context for controllers, but for now this will have to do.
This change removes [Activate] from ViewComponents. Accessing context should be done through [ViewComponentContext]. Accessing services should be done though constructor injection.
This change removes [Activate] support from TagHelpers. TagHelpers which need access to context should use [ViewContext] to have it injected. To access services, use constructor injection.
Closing this because we've done some parts of the plan discussed above and that's our resting place for beta-5. By no means do I want to stop the discussion here or avoid discussion of the changes we did decide to make. See a general announcement here: aspnet/Announcements#28 TLDR summary:
|
Is there a reason why these are named differently?
@inject
[Activate]
Why not
[Inject]
and@inject
, or[Activate]
and@activate
?The text was updated successfully, but these errors were encountered: