Veranstaltung
RSS


Wiki



Suche

»
Erweiterte Suche »

Sponsoren

  • Addison-Wesley
  • CIBER AG
  • CID GmbH
  • colima communications GmbH
  • COMPAREX Deutschland AG
  • COMPAREX Deutschland AG
  • devcoach
  • FIO SYSTEMS AG
  • Galileo Press
  • Gurock Software GmbH
  • Hays AG
  • Infragistics Europe LLC
  • Intel GmbH
  • Intel GmbH
  • itCampus Software- und Systemhaus GmbH
  • JetBrains
  • Keßler Solutions GmbH
  • Microsoft Deutschland GmbH
  • Microsoft Deutschland GmbH
  • Microsoft Deutschland GmbH
  • Microsoft Press
  • NDepend
  • Neue Mediengesellschaft Ulm mbH/dotnetpro
  • OBJEKTspektrum bzw. SIGS-Datacom GmbH
  • Redgate
  • Sage HR Solutions AG
  • Saxonia Systems AG
  • Schenker Notebooks
  • Teilnehmer des .NET Open Space
  • Telerik
  • Typemock
  • Wufoo

Partner

  • ALT.NET User Group Berlin
  • Bonn-to-Code.Net
  • .NET Developers Group Berlin Brandenburg
  • .NET Developer Group Braunschweig
  • .NET User Group Dresden
  • .NET User Group Hamburg
  • .NET User Group Koblenz
  • .NET User Group Köln
  • .NET User Group Frankfurt
  • .NET User Group Niederrhein
  • .NET User Group Rostock
  • INETA Deutschland
  • Professional .NET 2011

Arbeitsbereich Clean Code

RSS

IoC

interface IEmailSender
{
  void SendEmail(string recipient);
}

class FakeEmailSender : IEmailSender
{
  public void SendEmail(string recipient) {};
}


class BusinessComponent
{
  IEmailSender _sender;
  
  public BusinessComponent(IEmailSender sender)
  {
    _sender = sender;
  }
  
  public void DoSomething()
  {
    //...
    _sender.SendEmail("agross@therightstuff.de");
  }
}

class TestFixture {
  public void SomeTest()
  {
    var sut = new BusinessComponent(A.Fake<IEmailSender>());
  }
}

class MyRegistry : Registry
{
  MyRegistry()
  {
    For<IEmailSender>().Use<FakeEmailSender>().Ctor<string>("sender", c=>c.AppSetting("sender"));
    
    // Generic specialization durch den container
    For(typeof(IValidator<>)).Use(typeof(Validator<>));
  }
}

class Foo : IFoo, IBar

// Windsor 2.5
Component.For<IFoo>().Forward<IBar>().ImplementedBy<Foo>().Singleton();
//Component.For<IBar>().ImplementedBy<Foo>().Singleton();

Singleton
Transient
Pooled
PerWebRequest
PerThread

PerOperation
PerDomain
PerService

class PdfExport : IExporter {}
class XmlExport : IExporter {}
class TxtExport : IExporter {}
class CsvExport : IExporter {}

class UsesExporter{
  UsesExporter(Func<string, IExporter> factory)
  {
    factory("c:\x.pdf");
  }
}

class Validator<T> : IValidator<T>
{
  public void Validate(T obj)
  { ... }
}

ObjectFactory.Configure(x => x.Scan(s => { s.FromApplicationBaseDirectory(); s.LookForRegistries(); });

var bc = ObjectFactory.GetInstance<BusinessComponent>();
bc.DoSomething();

class Foo
{
  Foo()
  {
    _bar = ObjectFactory.GetInstance<IBar>();
  }
}

class CustomerApplicationService{
  ctor(IEmailSender sender, IRepository<Customer> customers)
  {
    _sender = sender;
  }
  
  public RegisterPaymentFor(int customerId, decimal amount)
  {
    var c = _customers.GetById(customerId),
    c.RegisterPayment(amount, _sender);
  }
}

class RegisterPaymentForCustomerHandler : IHandleMessage<RegisterPayment> {
  ctor(IEmailSender sender, IRepository<Customer> customers)
  {
    _sender = sender;
  }
  
  public Handle(RegisterPayment message)
  {
    var c = _customers.GetById(message.CustomerId),
    c.RegisterPayment(message.Amount, _sender);
  }
}


class Customer {
  public void RegisterPayment(decimal amount, IEmailSender sender)
  {
    _total += amount;
    if (_total > 10000)
    {
      sender.SendEmail(this);
    }
  }
}