コード例 #1
0
ファイル: command.cs プロジェクト: toshimaru/DesignPattern
        static void Main(string[] args)
        {
            var receiver = new Receiver ();
              var command = new ConcreteCommand (receiver);
              var invoker = new Invoker ();

              invoker.Command = command;
              invoker.ExecuteCommand ();
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: touhid91/DesignPatterns
        public static void Main()
        {
            IReceiver receiver = new Receiver();
            Command command = new ConcreteCommand(receiver);
            Invoker invoker = new Invoker();

            invoker.SetCommand(command);
            invoker.ExecuteCommand();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Receiver receiver = new Receiver();
            Command command = new ConcreteCommand(receiver);
            Invoker invoker = new Invoker();
            invoker.SetCommand(command);
            invoker.ExecuteCommand();

            Console.Read();
        }
コード例 #4
0
  public static void Main( string[] args )
  {	
    // Create receiver, command, and invoker
    Receiver r = new Receiver();
    Command c = new ConcreteCommand( r );
    Invoker i = new Invoker();

    // Set and execute command
    i.SetCommand(c);
    i.ExecuteCommand();

  }
コード例 #5
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Demo()
        {
            // Create receiver, command, and invoker
            Receiver receiver = new Receiver();
            Command command = new ConcreteCommand(receiver);
            Invoker invoker = new Invoker();

            // Set and execute command
            invoker.SetCommand(command);
            invoker.ExecuteCommand();

            // Wait for user
            Console.ReadKey();
        }
 public ServiceThatDependsOnRepository(IRepository repository, IContextualLogger logger,
     ConcreteCommand justAnExtraArgumentToMakeUsFindBugsFaster)
 {
     this.InjectedRepository = (RepositoryThatDependsOnLogger)repository;
     this.InjectedLogger = (ContextualLogger)logger;
 }
コード例 #7
0
        public void GetInstance_CalledMultipleTimesOnOnInstanceRegisteredAsSingleFunc_CallsTheInitializerJustOnce()
        {
            // Arrange
            int expectedTimesDelegateGetsCalled = 4;
            int actualTimesDelegateGotCalled = 0;

            var container = ContainerFactory.New();

            container.RegisterInitializer<ICommand>(c => { actualTimesDelegateGotCalled++; });

            var singleton = new ConcreteCommand();

            container.Register<ICommand>(() => singleton);

            // Act
            container.GetInstance<ICommand>();
            container.GetInstance<ICommand>();
            container.GetInstance<ICommand>();
            container.GetInstance<ICommand>();

            // Assert
            Assert.AreEqual(expectedTimesDelegateGetsCalled, actualTimesDelegateGotCalled,
                "The container will even call the initializer on instances that are passed in from the " +
                "outside, and since the delegate is registered as transient, the initializer should be " +
                "called each time.");
        }