One of the most important features of any proper development architecture, environment or process, is that the synergy (network) effects accumulate, if you keep doing the right things. IoC/DI, unit testing and TDD, continuous integration - all these just form up the external side of how everything works. They simply help (or force) to shape the logics of the development to make everything fold smoothly and let your solutions accumulate the benefits.
Now, let us get back to the IoC+ORM series and take one more look at the ICommand implementation from the last post. It could be improved quite a bit:
public sealed class DisableAllAccounts : ICommand
{
private readonly IRepository<Account> _accounts;
private readonly ILog _log;
public DisableAllAccounts(IRepository<Account> accounts, ILog log)
{
_accounts = accounts;
_log = log;
}
public void Execute()
{
_log.Write("Disabling accounts:");
_accounts.CriteriaString = "Disabled=0";
foreach (var account in _accounts)
{
_log.Write(account.Name);
account.Disabled = true;
account.Save();
}
}
}
Things become better as we throw out things that do not fit well. So let us remove our custom IRepository<> from this picture (along with the FireCollection behind it) and get rid of the string literal in favor of something that is compiler-checked
Continue reading ‘How to use ORM (XPO), IoC, C# 3.5 syntax, Linq and .NET 2.0 together?’
Latest Comments