This repository has been archived by the owner. It is now read-only.

Autofac

hmemcpy edited this page Feb 9, 2013 · 12 revisions

Autofac takes a slightly different approach for registering types, by providing the concrete type as the first parameter. The registration is done on the ContainerBuilder instance.

Manual registration

  • RegisterType<T> - registers a concrete type T
  • RegisterType(typeof(Type)) - non generic version
  • Register(c => new Foo(c.Resolve<IBar>())) - register with lambda expression (only the new Foo() is inspected)
  • More complex registrations, see this for example.

Convention-based registration

  • RegisterAssemblyTypes(params Assembly[]) - the following parameters are currently supported:
  • ThisAssembly property - only available when called within an Autofac Module
  • Assembly.GetExecutingAssembly()
  • typeof(Type).Assembly

The following filters can be applied in convention-based registration:

  • As<T> - can be applied several times
  • As(params[] Type) - currently supports typeof(Foo) expressions only
  • AsClosedTypesOf
  • AsImplementedInterfaces
  • AssignableTo
  • InNamespaceOf<T>
  • InNamespace("Namespace")

Not (yet?) supported