public void DependencyInConstructor()
        {
            Type service = typeof( ISpamService );
            Type implementation = typeof( SimpleSpamService );
            Type serviceDep = typeof( IMailService );
            Type implementationDep = typeof( SimpleMailService );

            kernel.AddComponent( "a", service, implementation );
            kernel.AddComponent( "b", serviceDep, implementationDep );

            IComponentModel model = new DefaultComponentModelBuilder(kernel).BuildModel(
                "a", service, implementation );

            Hashtable serv2Handler = new Hashtable();
            serv2Handler[ serviceDep ] = kernel.GetHandlerForService( serviceDep );

            BaseComponentFactory factory = new BaseComponentFactory(
                kernel, null, model, serv2Handler );

            Object instance = factory.Incarnate();

            AssertNotNull( instance );
            AssertNotNull( instance as ISpamService );

            SimpleSpamService spamService = (SimpleSpamService) instance;
            AssertNotNull( spamService.m_mailService );

            factory.Etherialize( instance );
        }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        public BaseKernel()
            : base()
        {
            m_key2Handler = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
            m_subsystems = new Hashtable();
            m_facilities = new Hashtable();
            HandlerFactory = new BaseHandlerFactory();
            ModelBuilder = new DefaultComponentModelBuilder(this);
            LifestyleManagerFactory = new SimpleLifestyleManagerFactory();

            InitializeSubsystems();
        }
        public void TestApply()
        {
            IConcern concern = Create();
            AssertNotNull( concern );
            concern.Init( m_kernel );

            IComponentModel model =
                new DefaultComponentModelBuilder(m_kernel).BuildModel(
                    "a", typeof(IMyService), typeof(DummyComponent) );

            DummyComponent component = new DummyComponent();

            concern.Apply( model, component );

            AssertComponent( model, component );
        }
        public void AvalonServiceWithDependencies()
        {
            DefaultComponentModelBuilder builder =
                new DefaultComponentModelBuilder( m_kernel );

            Type service = typeof( ISpamService );
            Type implementation = typeof( AvalonSpamService );

            IComponentModel model =
                builder.BuildModel( "a", service, implementation );

            AssertNotNull( model );
            AssertNotNull( model.Logger );
            AssertNotNull( model.Configuration );
            AssertNotNull( model.Context );
            AssertNotNull( model.Dependencies );
            AssertEquals( 1, model.Dependencies.Length );
        }
        public void AvalonSimpleService()
        {
            DefaultComponentModelBuilder builder =
                new DefaultComponentModelBuilder( m_kernel );

            Type service = typeof( IMailService );
            Type implementation = typeof( AvalonMailService );

            IComponentModel model =
                builder.BuildModel( "a", service, implementation );

            AssertEquals( Apache.Avalon.Framework.Lifestyle.Singleton, model.SupportedLifestyle );
            AssertNotNull( model );
            AssertNotNull( model.Logger );
            AssertNotNull( model.Configuration );
            AssertNotNull( model.Context );
            AssertNotNull( model.Dependencies );
            AssertEquals( 0, model.Dependencies.Length );
        }
 public void CreateComponentModelBuilder()
 {
     m_builder = new DefaultComponentModelBuilder( m_kernel );
 }
        public void DependencyInSetMethods()
        {
            Type service = typeof( IMailMarketingService );
            Type implementation = typeof( SimpleMailMarketingService );
            Type serviceDep1 = typeof( IMailService );
            Type implementationDep1 = typeof( SimpleMailService );
            Type serviceDep2 = typeof( ICustomerManager );
            Type implementationDep2 = typeof( SimpleCustomerManager );

            kernel.AddComponent( "a", service, implementation );
            kernel.AddComponent( "b", serviceDep1, implementationDep1 );
            kernel.AddComponent( "c", serviceDep2, implementationDep2 );

            IComponentModel model = new DefaultComponentModelBuilder(kernel).BuildModel(
                "a", service, implementation );

            Hashtable serv2Handler = new Hashtable();
            serv2Handler[ serviceDep1 ] = kernel.GetHandlerForService( serviceDep1 );
            serv2Handler[ serviceDep2 ] = kernel.GetHandlerForService( serviceDep2 );

            BaseComponentFactory factory = new BaseComponentFactory(
                kernel, null, model, serv2Handler );

            Object instance = factory.Incarnate();

            AssertNotNull( instance );
            AssertNotNull( instance as IMailMarketingService );

            SimpleMailMarketingService mailMarketing = (SimpleMailMarketingService) instance;
            AssertNotNull( mailMarketing.m_mailService );
            AssertNotNull( mailMarketing.m_customerManager );

            mailMarketing.AnnoyMillionsOfPeople( "Say something" );

            factory.Etherialize( instance );
        }
        public void NoArgumentsConstructor()
        {
            Type service = typeof( IMailService );
            Type implementation = typeof( SimpleMailService );

            kernel.AddComponent( "a", service, implementation );

            IComponentModel model = new DefaultComponentModelBuilder(kernel).BuildModel( "a", service, implementation );

            BaseComponentFactory factory = new BaseComponentFactory(
                kernel, null,
                model, new Hashtable() );

            Object instance = factory.Incarnate();

            AssertNotNull( instance );
            AssertNotNull( instance as IMailService );

            factory.Etherialize( instance );
        }
        public void SimpleComponent()
        {
            DefaultComponentModelBuilder builder =
                new DefaultComponentModelBuilder( m_kernel );

            Type service = typeof( IMailService );
            Type implementation = typeof( SimpleMailService );

            IComponentModel model =
                builder.BuildModel( "a", service, implementation );

            AssertNotNull( model );
            AssertNotNull( model.Logger );
            AssertNotNull( model.Name );
            AssertNotNull( model.Configuration );
            AssertNotNull( model.Context );
            AssertNotNull( model.Dependencies );
            AssertNotNull( model.Properties );

            AssertEquals( 0, model.Properties.Count );
            AssertEquals( 0, model.Dependencies.Length );
            AssertEquals( "a", model.Name );
            AssertEquals( Avalon.Framework.Lifestyle.Transient, model.SupportedLifestyle );
            AssertEquals( Avalon.Framework.Activation.Undefined, model.ActivationPolicy );
        }
        public void DependencyInSetters()
        {
            DefaultComponentModelBuilder builder =
                new DefaultComponentModelBuilder( m_kernel );

            Type service = typeof( IMailMarketingService );
            Type implementation = typeof( SimpleMailMarketingService );

            IComponentModel model =
                builder.BuildModel( "a", service, implementation );

            AssertNotNull( model );
            AssertNotNull( model.Logger );
            AssertNotNull( model.Configuration );
            AssertNotNull( model.Context );
            AssertNotNull( model.Dependencies );
            AssertEquals( 2, model.Dependencies.Length );
        }