
These things make the class more easily testable, configurable and maintainable. It is independent of how the user is notified – the notifier could send an email, write to the event log, or print to the console.It is independent of persistence – the IQueryable that holds the memos might be backed by a database table, a structured file, or an in-memory collection.It accepts all of its dependencies as parameters, in this case to the constructor.The following aspects of this class come as a direct result of using a dependency-injected style: Var overdueMemos = _memos.Where(memo => memo.DueAt < DateTime.Now) Check for overdue memos and alert the notifier of any that are found. public MemoChecker(IQueryable memos, IMemoDueNotifier notifier) Construct a memo checker with the store of memos and the notifier // that will be used to display overdue memos.
ULTRAMAILER BASIC V 3.5 CODE
Checking for Overdue MemosĪt the core of the application is the MemoChecker component, which looks like this:Ĭopy Code // A MemoChecker. In the interests of brevity, XML comments, argument checking, and exception handling are elided from all of the code samples. The application is a console program that checks a list of memos, each with a due date, and notifies the user of the ones that are overdue.Ī lot of simplifications have been made in the example code. If you're already using a DI container and want to get a feel for how Autofac is different, you may wish to skip ahead briefly and check out the code in the Autofac in Applications section. This article uses an example to demonstrate the most basic techniques for creating and wiring together application components, then goes on to discuss the most important features of Autofac. That is not to say that it is simplistic it has most of the features offered by other DI containers, and many subtle features that help with the configuration of your application, managing components' life-cycles, and keeping the dependencies under control. The result is that Autofac supports a wide array of application designs with very little additional infrastructure or integration code, and with a lower learning curve. It is designed around the premise that it is wasteful to work in such a powerful language as C# but to lose that power to purely reflection-based APIs like those prevalent in the other. Fine-Grained Control of Component LifetimesĪutofac is an open-source dependency injection (DI) or inversion of control (IoC) container developed on Google Code.Īutofac differs from many related technologies in that it sticks as close to bare-metal C# programming as possible.Registering a Component with its Implementation Type.Registering a Component Created with an Expression.
