helitonjr / ActivateAnything

ActivateAnything will make an extreme best effort to find and instantiate a concrete class which is assignable to a Type

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NetCore 2.1 Build and Test

ActivateAnything

Activate.New<T>()

…will make an extreme effort to find and instantiate a concrete class which is assignable to a Type, whether or not the Type is concrete, whether or not the Type has constructor dependencies, whether or not a suitable concrete subtype is found in any currently loaded Assembly.

The attempt to find and instantiate suitable Types is driven by three kinds of IActivateAnythingRule.

  • IActivateInstanceRule simply returns an instance of a concrete type.
  • IFindTypeRule provides rules for where to look for candidate concrete subtypes of an abstract type
  • IChooseConstructorRule rules for how to choose between constructors when a concrete Type has been chosen.

The extremity of the effort lies in its recursive attempt to find and construct the dependencies.

The default ruleset will

  • Search first the currently executing assembly, then its references, then its base directory, then the current working directory
  • Prefer constructors with more parameters over constructors with fewer.

Customise or replace the default ruleset with the provided rules or custom rules.

Example Usage

See FixtureBase : reduce the cost of Unit Testing by automating setup and the injection of fakes.

About

ActivateAnything will make an extreme best effort to find and instantiate a concrete class which is assignable to a Type


Languages

Language:C# 98.9%Language:PowerShell 1.1%