public RequiresThreeDisposables(
     Disposable first,
     Disposable2 second,
     Disposable3 third)
 {
     First  = first;
     Second = second;
     Third  = third;
 }
Exemplo n.º 2
0
 public Disposable2(Disposable3 disposable3)
 {
     this.disposable3 = disposable3;
 }
Exemplo n.º 3
0
 public Disposable1(Service1 service1, Disposable3 disposable3)
 {
     this.service1 = service1;
     this.disposable3 = disposable3;
 }
        public void Execute()
        {
            //
            // 通常パターン.
            //
            using (var disposable1 = new Disposable1())
            {
                using (var disposable2 = new Disposable2())
                {
                    using (var disposable3 = new Disposable3())
                    {
                        Output.WriteLine("Dispose Start..");
                    }
                }
            }

            //
            // 通常パターン: DisposableManager利用.
            //
            using (var manager = new DisposableManager())
            {
                manager.Add(new Disposable1());
                manager.Add(new Disposable2());
                manager.Add(new Disposable3());

                Output.WriteLine("Dispose Start..");
            }

            //
            // 条件が存在し、作成されないオブジェクトが存在する可能性がある場合.
            //
            Disposable1 dispose1 = null;
            Disposable2 dispose2 = null;
            Disposable3 dispose3 = null;

            var isDispose2Create = false;

            try
            {
                dispose1 = new Disposable1();

                if (isDispose2Create)
                {
                    dispose2 = new Disposable2();
                }

                dispose3 = new Disposable3();
            }
            finally
            {
                Output.WriteLine("Dispose Start..");
                DisposeIfNotNull(dispose1);
                DisposeIfNotNull(dispose2);
                DisposeIfNotNull(dispose3);
            }


            //
            // 条件あり: DisposableManager利用.
            //
            dispose1 = null;
            dispose2 = null;
            dispose3 = null;

            using (var manager = new DisposableManager())
            {
                dispose1 = manager.Add(new Disposable1());

                if (isDispose2Create)
                {
                    dispose2 = manager.Add(new Disposable2());
                }

                dispose3 = manager.Add(new Disposable3());

                Output.WriteLine("Dispose Start..");
            }
        }
 public RequiresScopeAndDisposable3(ContainerScope scope, Disposable3 disposable)
 {
     Scope      = scope;
     Disposable = disposable;
 }
Exemplo n.º 6
0
 public Disposable2(Disposable3 disposable3)
 {
     this.disposable3 = disposable3;
 }
Exemplo n.º 7
0
 public Disposable1(Service1 service1, Disposable3 disposable3)
 {
     this.service1    = service1;
     this.disposable3 = disposable3;
 }