public void HybridAvalonComponent() { IAvalonKernel container = new DefaultAvalonKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) ); container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService2) ); IHandler handler = container[ "b" ]; ISpamService service = handler.Resolve() as ISpamService; AssertNotNull( service ); service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" ); handler.Release( service ); }
public void AvalonComponentWithUnsatisfiedDependencies() { IAvalonKernel container = new DefaultAvalonKernel(); container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService) ); IHandler handler = container[ "b" ]; try { ISpamService service = handler.Resolve() as ISpamService; Fail("Dependencies unsatisfied for this component. Resolve should fail."); } catch(HandlerException) { // Expected. } }
public void TransientDependencyDisposal() { IAvalonKernel container = new DefaultAvalonKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService2) ); container.AddComponent( "b", typeof(ISpamService2), typeof(AvalonSpamService3) ); IHandler handler = container[ "b" ]; ISpamService2 spamService = handler.Resolve() as ISpamService2; AssertNotNull( spamService ); AssertNotNull( spamService.MailService ); AvalonMailService mailService = (AvalonMailService) spamService.MailService; Assert( !mailService.disposed ); handler.Release( spamService ); Assert( "A transient component should have been disposed", mailService.disposed ); }
public void Creation() { IAvalonKernel kernel = new DefaultAvalonKernel(); AssertNotNull(kernel); }
public void SimpleUsage() { IAvalonKernel container = new DefaultAvalonKernel(); container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) ); IHandler handler = container[ "a" ]; IMailService service = handler.Resolve() as IMailService; AssertNotNull( service ); service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?"); handler.Release( service ); }
public void SimpleAvalonComponent() { IAvalonKernel container = new DefaultAvalonKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService2) ); IHandler handler = container[ "a" ]; IMailService service = handler.Resolve() as IMailService; AssertNotNull( service ); AvalonMailService realInstance = (AvalonMailService) service; Assert( realInstance.initialized ); Assert( realInstance.configured ); Assert( !realInstance.disposed ); service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?"); handler.Release( service ); Assert( realInstance.disposed ); }