jammycakes / factoryfactory

Yet another IOC container for .NET, designed from the ground up to support the ASP.NET Core DI abstractions.
MIT License
0 stars 1 forks source link

Convention-based registration #16

Open jammycakes opened 5 years ago

jammycakes commented 5 years ago

Some notes:

jammycakes commented 5 years ago

The infrastructure is in place: conventions can be registered through custom implementations of IServiceDefinition; this means that they will be resolved in the order of registration.

Main thing needed is to create a fluent convention registration API. Something like this:

module.Given(type => Criterion(type))
    .Find(type => GetImplementations(type));

Possible shortcuts:

module.Given
    .Condition(type => type.Name.StartsWith("I") && type.IsInterface)
    .Condition(type => type.ImplementsOrExtends(IRepository))
    .FindMatchingImplementationInSameNamespace();
module.Given
    .Interface()
    .In(assembly)
    .In(namespace, ...)
    .Implementing<otherType>()
    .FindMatchingImplementationsInSameAssembly();
module.Given
    .Interface()
    .In(assembly, namespace, includeSubsidiaryNamespaces)
    .FindMatchingImplementationsInAssembly(implementingAssembly);