Coder Social home page Coder Social logo

autofac / autofac Goto Github PK

View Code? Open in Web Editor NEW
4.4K 4.4K 833.0 89.36 MB

An addictive .NET IoC container

Home Page: https://autofac.org

License: MIT License

C# 99.42% PowerShell 0.58%
autofac c-sharp dependency-injection ioc-container netcore netstandard

autofac's Introduction

Autofac character Autofac logo

Autofac is an IoC container for Microsoft .NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. This is achieved by treating regular .NET classes as components.

Build status codecov NuGet

Autofac on Stack Overflow Join the chat at https://gitter.im/autofac/autofac

Get Packages

You can get Autofac by grabbing the latest NuGet package. There are several application integration and extended functionality packages to choose from. If you're feeling adventurous, continuous integration builds are on MyGet.

Release notes are available on GitHub.

Get Help

Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.

Get Started

Our Getting Started tutorial walks you through integrating Autofac with a simple application and gives you some starting points for learning more.

Super-duper quick start:

Register components with a ContainerBuilder and then build the component container.

var builder = new ContainerBuilder();

builder.Register(c => new TaskController(c.Resolve<ITaskRepository>()));
builder.RegisterType<TaskController>();
builder.RegisterInstance(new TaskController());
builder.RegisterAssemblyTypes(controllerAssembly);

var container = builder.Build();

Resolve services from a lifetime scope - either the container or a nested scope:

var taskController = container.Resolve<TaskController>();

There is a growing number of application integration libraries that make using Autofac with your application a snap. Support for several popular frameworks is also available through the "Extras" packages.

Intrigued? Check out our Getting Started walkthrough!

Project

Autofac is licensed under the MIT license, so you can comfortably use it in commercial applications (we still love contributions though).

File issues in the repo with the associated feature/code.

Sponsors

Autofac is supported by AWS. Thanks for your contribution!

Contributing / Pull Requests

Refer to the Contributor Guide for setting up and building Autofac source.

You can also open this repository right now in VS Code.

autofac's People

Contributors

abdullin avatar adamralph avatar alexandrnikitin avatar alexmg avatar alistairjevans avatar alsami avatar botinko avatar brendankowitz avatar carlhoerberg avatar cvertex avatar damirainullin avatar drusellers avatar eugbaranov avatar ivanferic avatar jamesottaway avatar mashbrno avatar nblumhardt avatar ownageismagic avatar plillevold avatar raishey avatar raymondhuy avatar rogerkratz avatar romerod avatar sergeipavlov avatar sheastrickland avatar shiftkey avatar tillig avatar twsouthwick avatar vonogre avatar zacateras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autofac's Issues

New events on ContainerBuilder

From [email protected] on February 29, 2008 23:14:40

Enhancement : Important/Urgent (in order to have global behavior like
creating proxy instance for component with special attribut, useful when
implementing a proxy cache/transaction solution)

The ContainerBuilder should expose a global event

Event fired when a new component is registered
.OnRegistered(EventHandler handler)

This will act as a global inspector during component registration

Original issue: http://code.google.com/p/autofac/issues/detail?id=36

Add extended properties to XML configuration syntax

From [email protected] on March 13, 2008 21:39:23

I.e. members to be added to the ExtendedProperties dictionary attached to
the component.

Unlike most other configuration file elements, there is no way to determine
the actual concrete type required. In addition to name and value, then, it
is probably a good idea to add an optional type attribute so that
non-string values can be converted.

Original issue: http://code.google.com/p/autofac/issues/detail?id=45

Create an automatic registration extension

From [email protected] on February 19, 2008 08:13:49

As an alternative to registering components (e.g. controllers) by
enumerating types, provide an automatic predicate-based registrar that at
the fundamental level looks like:

builder.RegisterAutomatically(s => ...).WithScope( InstanceScope .Factory);

...but is built on top of to provide:

builder.RegisterTypeAutomatically(t => ...);

...and possibly even:

builder.RegisterSubclassesAutomatically();

Original issue: http://code.google.com/p/autofac/issues/detail?id=31

Ideas around immutability

From [email protected] on January 03, 2008 17:46:40

To simplify the implementation of caching it seems like a good idea to make
the typical container implementation immutable (from the perspective of
registrations.)

ContainerBuilder can be used to provide all registrations at construction
time. This will enable aggressive caching of reflection data etc.

There may not be a direct relationship between the mutable and immutable
containers, this needs to be investigated. There may not even be a need for
a mutable version of the container if the use cases can be covered by other
means (e.g. dynamic lambda registrations.)

Will most likely lead to API changes, hence the 2.0 milestone.

Original issue: http://code.google.com/p/autofac/issues/detail?id=19

Mono Test Failures

From [email protected] on December 15, 2007 19:18:01

  1. Autofac.Tests.Component.Ownership.DisposerFixture.ReferenceNotHeld :
    Expected: False
    But was: True

at Autofac.Tests.Component.Ownership.DisposerFixture.ReferenceNotHeld ()
[0x00000]
at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) [0x00000]

Original issue: http://code.google.com/p/autofac/issues/detail?id=17

Create a full Tagged Contexts feature

From [email protected] on February 10, 2008 10:58:37

Named Contexts (to be implemented as Tagged Contexts so that, for example,
enumerations rather than strings could be used for tags) control
instantiation in architectures using deeply nested container hierarchies.

This will be one of the first of the 'Autofac Extras' - optional features
deployed separately that extend the container.

Part of this project will be to explore the extensibility mechanisms
already available and how these might be further enhanced so that the core
of Autofac can be kept lean.

Original issue: http://code.google.com/p/autofac/issues/detail?id=28

Support for .NET 2.0

From [email protected] on February 05, 2008 09:30:02

What steps will reproduce the problem? 1. autofac currently requires .NET 3.5, while .NET 2.0 will mean that you
don't get all the beauty of C#3.0, It looks to be a very useful library. What is the expected output? What do you see instead? A .NET 2.0 version could still utilize a lot of autofac. What version of the product are you using? On what operating system? 1.0.7.33480 Please provide any additional information below.

Original issue: http://code.google.com/p/autofac/issues/detail?id=25

Simplified interfaces to handling component registrations

From [email protected] on March 10, 2008 19:38:22

IComponentRegistration and the related functionality in IContainer is
fairly terse - you can get a lot of information from them but not in the
most straightforward manner.

It would be good to provide extension methods designed to assist people
writing container extensions, either in Autofac.Component or a nested
namespace.

Some examples:

  • Interfaces provided by a component
  • Names applied to a component
  • Components supporting an interface
  • Components with a particular name

Also some discussion from Luke Schafer here: http://codesugar.com/index.php?itemid=5 .

Original issue: http://code.google.com/p/autofac/issues/detail?id=43

Expose implementation type

From [email protected] on March 10, 2008 20:19:26

IComponentRegistration does not provide the implementation type for a
service. This is because none of the core should depend on this information

  • in many cases it is not available or cannot be reliably determined, e.g. in:

builder.Register(c => SomeClass.GetService());

...where GetService() returns an interface.

In many other cases, this information is available and would be useful in
implementing container extensions.

The implementation type can be reliably inferred when registering:

  • a System.Type
  • an instance
  • a delegate whose return type is concrete (even in the abstract case)

When this information is not available, there are a few strategies:

  • don't provide anything at all (e.g. null? no Autofac properties
    currently return null - possibly TryGetImplementationType? hmm) - prevents
    confusion
  • return typeof(System.Object) - useless but no NullReferenceException worries
  • return any known interface type (a bit unpredictable)
  • design the API in such a way that it is natural to fall back to
    determining the type of each instance (inefficient but correct.)

Changes potentially required in Component.Registration and subclasses, as
well as Registrar and subclasses.

Original issue: http://code.google.com/p/autofac/issues/detail?id=44

Reinstate Accumulating Collections

From [email protected] on November 11, 2007 12:09:53

Accumulating collections were removed in revision r22 .

This feature will provide a great foundation for building plugin systems
etc, however the original implementation was in the container core rather
than a facility. To avoid breaking API changes it was removed for the 1.0
release.

The new implementation of this feature should:

  • Work predictably with nested containers
  • Delegate element creation to the container using the string-keyed
    TryResolve()
  • Respect instance scope
  • Use an explicit syntax to accumulate element registrations, so that a
    default service of the element type can be registered along side the
    collection type

Original issue: http://code.google.com/p/autofac/issues/detail?id=2

Autofac.DotNet2.dll is not strongly signed.

From [email protected] on February 13, 2008 15:16:20

What steps will reproduce the problem? 1. Use Autofac.DotNet.dll in a assembly that is strongly signed. What version of the product are you using? On what operating system? Autofac.DotNet2.dll version 1.0.8.190 Please provide any additional information below. We ship strongly signed assemblies so we can't use Autofac unless it is
strongly signed or uses delay signing.

Is it possible to patch the current version and sign it?

Original issue: http://code.google.com/p/autofac/issues/detail?id=29

Simplify circular ctor/property and property/property dependencies

From [email protected] on November 14, 2007 06:19:28

In v. 1.0.1 to handle circular dependencies a manual 'hack' must be used in
the activators/OnActivated handlers to wire up circular deps (the usual way
to inject properties is OnActivat_ing_.)

This use case can be greatly improved if the OnActivated handlers run once
the component is made available to the container - InjectProperties can be
used as normal (though OnActivating is really the correct place in other
scenarios.)

The only problem I can see with this is that doing so in factory lifecycle
scenarios will cause an infinite recursion - perhaps the circular reference
checker can be extended to be permissive about a single loop but fail after
more than one identical recursion is detected?

Original issue: http://code.google.com/p/autofac/issues/detail?id=9

Expose an interface for containers

From [email protected] on January 25, 2008 22:41:34

IContainer currently exists inside Autofac as a means of communication
between elements of a container hierarchy. This will need to be renamed,
the exposed container interface will assume this name and will derive from
IContext to provide more of the Autofac.Container features. Two derived
interfaces - one exposing Register and the other not, might be appropriate.

Original issue: http://code.google.com/p/autofac/issues/detail?id=23

Create standard ASP.NET integration

From [email protected] on January 25, 2008 22:36:26

A pre-built integration for ASP.NET will benefit a large number of people
working in this environment.

Once this is done, the MVC integration should be layered on top of it.

The primary requirements of this integration are:

  • Injection of dependencies into Pages and Controls
  • Per-request container disposal
  • Minimisation of static dependencies
  • Flexible enough to accommodate multiple container scoping schemes
  • Easy to configure
  • Reasonably testable code...

Ideally Pages should be able to be injected into without disrupting the
inheritance hierarchy, e.g. by using [InjectProperties] or a similar
attribute in conjunction with an HTTP Module. Perhaps additional attributes
targeting members could be used to implement recursive injection.

Base classes for Pages and Controls should also be provided for those not
wishing to install an HTTP Module.

Original issue: http://code.google.com/p/autofac/issues/detail?id=22

Cast automatically when querying component by name (Enhancement)

From [email protected] on February 25, 2008 03:24:29

Enhancement
Avoid casting when query component by name

Must implement c.Resolve(new NamedService("Foo1"))
instead of (IFoo)c.Resolve(new NamedService("Foo1")

By the way, what is the rule the container applies to get a component for a
type if there's multiple components register for this type as in the above
sample.
As far I have see, it returns the last component register for this type, it
is always the case ?

Example
var builder = new ContainerBuilder();

        builder.Register<Foo1>().As<IFoo>().Named("Foo1");

        builder.Register(c =>
            new Foo2(
                (IFoo)c.Resolve(new NamedService("Foo1")))
            ).As<IFoo>().Named("Foo2");

        var container = builder.Build();
        IFoo foo = container.Resolve<IFoo>();

Original issue: http://code.google.com/p/autofac/issues/detail?id=32

Create the canonical 'Startable' module

From [email protected] on February 28, 2008 08:24:57

To enable and demonstrate container extensibility, add a version of the
typical 'startable' facility that works effectively through an orthogonal
implementation with minimal performance overheads.

E.g.

builder.Register(new StartableModule(s => s.Start()));

Should Start() any component instance created by the container, regardless
of whether the registration happens before or after the registration of the
Startable module.

IStartable in this instance is a placeholder - any type should be able to
be used as this maintains the unintrusiveness of the container.

To make this happen, the following APIs must be exposed:

IEnumerable IContainer.ComponentRegistrations
event IContainer.ComponentRegistered

To improve developer experience the above will be augmented with:

IComponentRegistration IContainer.DefaultRegistrationFor(Service service)

And possibly:

IEnumerable RegistrationsProviding(Service service)

Although the latter can easily be obtained using ComponentRegistrations and
a Select predicate.

The Module base type will be extended to hide the mechanics of enumerating
existing registrations and attaching to new ones with one virtual method:

virtual void AttachToRegistration(IContainer container,
IComponentRegistration registration)

Using this method the Startable facility can insert itself into the
OnActivated handler pipeline for only those components exposing IStartable.

Note, custom decommission steps will not be provided as IDisposable is the
correct place to handle this.

Original issue: http://code.google.com/p/autofac/issues/detail?id=34

Separate component descriptors from registration?

From [email protected] on March 04, 2008 19:09:59

This interface represents two distinct pieces of the registration - its
descriptor (Id, Services, ...) and the registration that performs the
necessary mechanics in a single container. Might be appropriate to move
'descriptor' part (that is shared between containers in a hierarchy) to a
separate interface and somehow link the two.

Original issue: http://code.google.com/p/autofac/issues/detail?id=41

CreateFromStrongFactory test fails under Mono 1.2.6

From [email protected] on December 15, 2007 19:19:12

Autofac.Tests.Component.Registration.ContextAwareDelegateRegistrationFixture.CreateFromStrongFactory
: System.Exception : Compiler Errors:
10,121 : Identifier expected

at
Autofac.Component.Activation.InterceptingDelegateActivator.BuildAssembly
(System.String source, IEnumerable`1 references) [0x00000]
at
Autofac.Component.Activation.InterceptingDelegateActivator.BuildImplementor
(System.Type creator) [0x00000]
at Autofac.Component.Activation.InterceptingDelegateActivator..ctor
(System.Type creator, Autofac.Component.ComponentActivator activator)
[0x00000]
at Autofac.Component.Registration.ContextAwareDelegateRegistration..ctor
(System.Type creator, Autofac.Component.ComponentActivator activator)
[0x00000]
at
Autofac.Tests.Component.Registration.ContextAwareDelegateRegistrationFixture.CreateFromStrongFactory
() [0x00000]
at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) [0x00000]

Original issue: http://code.google.com/p/autofac/issues/detail?id=18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.