コード例 #1
0
ファイル: Program.cs プロジェクト: KO55LEV/SOLID_Calculator
        static void Main(string[] args)
        {
            Console.WriteLine("App started");

            // Create your builder.
            var builder = new ContainerBuilder();

            //builder.RegisterType<OperationAdd>().As<ICalculatorOperation>();
            //builder.RegisterType<OperationSubtract>().As<ICalculatorOperation>();
            //builder.RegisterType<OperationMultiply>().As<ICalculatorOperation>();


            builder.RegisterAssemblyTypes(typeof(Calculator).Assembly).Where(x => x.Name.StartsWith("Operation"))
            .AsImplementedInterfaces();


            builder.RegisterType <PerformOperation>();

            var appContainer = builder.Build();
            var operations   = appContainer.Resolve <IEnumerable <ICalculatorOperation> >();


            //List<ICalculatorOperation> operations = new List<ICalculatorOperation>
            //{
            //    new OperationAdd(),
            //    new OperationSubsctract(),
            //    new OperationMultiply()
            //};

            var sum = new PerformOperation(operations).Operate("Multiply", 3, 4);

            var diOutput = appContainer.Resolve <PerformOperation>().Operate("Multiply", 3, 4);
        }