Skip to content

Yet another IOC container for .NET, designed from the ground up to support the ASP.NET Core DI abstractions.

License

Notifications You must be signed in to change notification settings

jammycakes/factoryfactory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FactoryFactory: an IOC container

Build status NuGet Pre Release Join the chat at https://gitter.im/factoryfactory/Lobby

FactoryFactory is a new IOC container for .NET. It has been built from the ground up to support the .NET Core abstractions out of the box, and it features a fluent interface, preconditions, custom lifecycles, and whatever other bits and pieces I see fit to introduce as I feel like it.

Usage:

Get it from NuGet:

Install-Package FactoryFactory

Create one or more modules to contain your service definitions:

using FactoryFactory;

public class MyModule: Module
{
    public Module(string[] args)
    {
        Define<IBlogRepository>().As<BlogRepository>();
        Define<IBlogService>().As<BlogService>();
        Define<DbContext>().As<DbContext>();
        Define<Program>().As<Program>(req => new Program(args));
    }
} 

Create a container from a Configuration, then get your root service:

var cfg = new Configuration(new MyModule());
using (var container = cfg.CreateContainer()) {
    container.GetService<Program>().Run();
}

In ASP.NET Core:

Install FactoryFactory.AspNet.DependencyInjection:

Install-Package FactoryFactory.AspNet.DependencyInjection

In Program.cs, add a call to .UseFactoryFactory() to your WebHostBuilder:

using FactoryFactory.AspNet.DependencyInjection;

/* snip */

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseFactoryFactory()
                .UseStartup<Startup>();

In Startup.cs, add a ConfigureContainer(Module) method:

public void ConfigureContainer(Module module)
{
    // Add your registrations to Module here
}

Roadmap:

  • 0.1:
    • Fully functional drop-in replacement for the ASP.NET Core container in Microsoft.Extensions.DependencyInjection.
    • Preconditions (untested)
    • Custom lifecycles
  • 0.2:
    • Interceptors
    • Documentation
  • 0.3:
    • Conventions
    • Direct registration of decorators
  • 0.4:
    • Feature switches
    • Automatic lazy resolution by dynamic proxy (separate project)
  • 1.0:
    • Validation
    • Resolve.From<T>() anywhere in any expression

About

Yet another IOC container for .NET, designed from the ground up to support the ASP.NET Core DI abstractions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages