This project is read-only.

ICommandActivatorContainer Interface

The ICommandActivatorContainer interface provides abstraction around how commands are instantiated by Theta.

    public interface ICommandActivatorContainer
    {
        InputCommand Get(Type inputCommandType);

    }


The ICommandActivatorContainer exposes a function, Get, which simply accepts a Type and returns an InputCommand. How the input command is returned (e.g., is it instantiated every time, is it cached, etc.) is determined by the implementation.

DefaultCommandActivatorContainer Implementation

By default, Theta uses the Credera.ThetaDefaultCommandActivatorContainer_.

    class DefaultCommandActivatorContainer : ICommandActivatorContainer
    {
        public InputCommand Get(Type inputCommandType)
        {
            return (InputCommand) Activator.CreateInstance(inputCommandType);
        }
    }

ICommandActivatorContainer Dependency Injection Implementation

However, a different implementation may be created to support dependency injection. This implementation uses Ninject.

    public class NinjectCommandActivator : ICommandActivatorContainer
    {
        private readonly IKernel _kernel;

        public NinjectCommandActivator(params INinjectModule[] modules)
        {
            _kernel = new StandardKernel(modules);
        }

        public InputCommand Get(Type inputCommandType)
        {
            return (InputCommand)_kernel.Get(inputCommandType);
        }
    }

Installing a Custom ICommandActivatorContainer

Using the example above, we can install the custom NinjectCommandActivator when the UtilityConsole is created.

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new UtilityConsole(null, new Type[]
                {
                    typeof(Modules.Packages.Module),
                    typeof(Modules.Variables.Module)
                }, new NinjectCommandActivator()));
        }

Last edited Mar 17 at 5:15 PM by jeffhewitt, version 1

Comments

No comments yet.