-
Notifications
You must be signed in to change notification settings - Fork 316
Adding support for service factories in IServiceDescriptor #102
Conversation
@loudej it doesn't look like Autofac has a way to get to the activation stack without private reflection or by intercepting all calls for activation and then looking at individual parameters to see if any of them match our factory. The latter might work, but I imagine it might affect perf. I thought it made sense to not have |
@@ -13,5 +13,10 @@ public class ServiceDescriptor : IServiceDescriptor | |||
// Exactly one of the two following properties should be set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be updated.
In fact, I think it would be even better to make these properties to be be getters only. Then we could have three constructors. This would give a compile time guarantee that only one of these three properties can ever be set if the ServiceDescriptor
type is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@pranavkm As discussed offline, this change requires a few extension methods for |
@pranavkm Is this going to be checked in any time soon? We want to use it in EF in this milestone. |
@halter73 sorry I hadn't noticed your comments earlier. Updated the PR. |
@divega I'll work on getting this in by next week. |
/// <param name="serviceType">The <see cref="Type"/> of the service.</param> | ||
/// <param name="instance">The instance implementing the service.</param> | ||
/// <param name="lifecycle">The <see cref="LifecycleKind"/> of the service.</param> | ||
public ServiceDescriptor(Type serviceType, object instance, LifecycleKind lifecycle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LifecycleKind.Singleton should be the only option if you are providing an instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Updated |
{ | ||
implementationType = Type.GetType(implementationTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type.GetType
does not throw if the type cannot be found and simply returns null.
You might want to talk to @lodejard before merging this so you two can decide how to reconcile these changes with the work he is doing in his feature-getservice-can-return branch. Otherwise you got a |
Fixes #64