public ICommand GetCommand(string commandName)
 {
     if (_commands.ContainsKey(commandName))
     {
         var template = _commands[commandName];
         var type     = template.GetType();
         var command  = _container.Activate <ICommand>(type);
         return(command);
     }
     else
     {
         return(null);
     }
 }
        protected override void RegisterConfigTypeInterface(IContainer container, Type interfaceType, TypeRegistration implementationRegistration, KeyValuePair <string, object>[] unmappedAttributes, XmlElement dependency)
        {
            if (interfaceType != typeof(IDataStore))
            {
                base.RegisterConfigTypeInterface(container, interfaceType, implementationRegistration, unmappedAttributes, dependency);
                return;
            }

            // IDataStore registrations get special treatment. The implementation must be disambiguated into Source and Target data stores,
            // which we do by wrapping it in a ConfigurationDataStore factory and manually registering the apropos interface.
            if ("sourceDataStore".Equals(dependency.Name, StringComparison.OrdinalIgnoreCase))
            {
                Func <object> wrapperFactory = () => new ConfigurationDataStore(new Lazy <IDataStore>(() => (IDataStore)container.Activate(implementationRegistration.Type, unmappedAttributes)));

                container.Register(typeof(ISourceDataStore), wrapperFactory, implementationRegistration.SingleInstance);

                return;
            }

            if ("targetDataStore".Equals(dependency.Name, StringComparison.OrdinalIgnoreCase))
            {
                Func <object> wrapperFactory = () => new ConfigurationDataStore(new Lazy <IDataStore>(() => (IDataStore)container.Activate(implementationRegistration.Type, unmappedAttributes)));

                container.Register(typeof(ITargetDataStore), wrapperFactory, implementationRegistration.SingleInstance);
            }
        }
Example #3
0
 /// <summary>
 /// Registers a specific interface to a type with the container.
 /// </summary>
 protected virtual void RegisterConfigTypeInterface(IContainer container, Type interfaceType, TypeRegistration implementationRegistration, KeyValuePair <string, object>[] unmappedAttributes, XmlElement dependency)
 {
     container.Register(interfaceType, () => container.Activate(implementationRegistration.Type, unmappedAttributes), implementationRegistration.SingleInstance);
 }