findConstructor method
- @protected
- ClassElement element
Returns the constructor on a given class
element
to use for injection.
This is determined via a heuristic, but in the future might be manually
configured with an annotation. Returns null
if no constructor that can
be used is found (i.e. is public).
Implementation
@protected
ConstructorElement? findConstructor(ClassElement element) {
// Highest priority is the unnamed (default constructor) if not abstract.
if (element.unnamedConstructor != null && !element.isAbstract) {
return element.unnamedConstructor;
}
// Otherwise, find the first public constructor.
// If the class is abstract, find the first public factory constructor.
return element.constructors.firstWhereOrNull(
(e) => e.isPublic && !element.isAbstract || e.isFactory);
}