|
GettingStarted
Getting up and running with Autofac.
AssembliesTo use Autofac, reference Autofac.dll in your project. ContainerBuilder can be found in the Autofac.Builder namespace. Register your components with ContainerBuilder then Build() a Container from which you can use them: var builder = new ContainerBuilder(); builder.Register<Foo>().As<IFoo>(); var container = builder.Build(); var foo = container.Resolve<IFoo>(); .NET 2.0 Support.NET 2.0 versions using LinqBridge are packaged in a separate zip file available from the Downloads page. If you are targeting .NET 2.0, reference both Autofac.dll and LinqBridge.dll. ResourcesThere's an introductory Autofac tutorial on CodeProject. The best way to get started is to pick and mix some articles from the wiki. Component Creation is a good place to start, and you'll need to take a peek at Instance Scope. Once you're familiar with Autofac, the Best Practices page can help you use it effectively in your applications. Some more advanced articles can be found On the Web. Building from SourceThe source code along with Visual Studio 2008 project files is available here. See the ASP.NET MVC Integration page about dependencies if you want to build that. Releases of Autofac are created with the included NAnt script - to execute, cd to /src and run: go.cmd integrate -D:Version=a.b.c.d Where a.b.c.d is the four part version number you want to build. To build the .NET 2.0 version, insert net20 immediately before integrate on the command-line. Binaries are output to /src/Build/Lib. See the Autofac.build file for additional targets and options. |
Sign in to add a comment
Can I recommend you have a startup guide for WinForms? or WPF. It would be nice if there were examples of how to go about registering interfaces in some sort of 'bootstrap' App.Load() method and then "how to access the container from other parts of the app?". There's guidance to suggest "not to pass container around" and "not access it from a singleton..." which begs the question, how do we access it then?
@spurrymoses, thanks for the suggestion, I'll add it to http://autofac.uservoice.com