Skip to content

Armature is lightweight and extremely easily extensible dependency injection framework

License

Notifications You must be signed in to change notification settings

Ed-Pavlov/Armature

Repository files navigation

If Armature has done you any good, consider support my future initiatives


Nuget Build & Test


Armature

Lightweight and extremely easily extensible dependency injection framework

Example of extensibility

See the project Tests.Extensibility to see the example of powerful extensibility possibility without changing the framework itself. It adds support for Maybe as an injected value.

Examples of using

var builder = new Builder(BuildStage.Cache, BuildStage.Initialize, BuildStage.Create)
{
  new SkipAllUnits
  {
    // inject into constructor
    new IfFirstUnit(new IsConstructor())
     .UseBuildAction(
        new TryInOrder(
          new GetConstructorByInjectPointId(),
          new GetConstructorWithMaxParametersCount()
        ),
        BuildStage.Create),
    new IfFirstUnit(new IsParameterInfoList())
     .UseBuildAction(new BuildMethodArgumentsInDirectOrder(), BuildStage.Create),
    new IfFirstUnit(new IsParameterInfo())
     .UseBuildAction(new BuildArgumentByParameterType(), BuildStage.Create)
  }
};


builder
 .TreatOpenGeneric(typeof(ISubject<>))
 .AsCreated(typeof(Subject<>));

builder
 .Treat<Subject>(tag)
 .AsIs()
 .InjectInto(Constructor.WithParameters<int, string, Stream>());

builder
 .Treat<Subject>()
 .AsIs()
 .InjectInto(Constructor.MarkedWithInjectAttribute(Subject.InjectPointId));

builder
 .Treat<ISubject>()
 .AsCreated<Subject>()
 .AsSingleton();

builder
  .Building<ISubject>()
  .Building<Subject>()
  .TreatAll()
  .UsingArguments(logger);