Exemplo n.º 1
0
        public IFuture <TR> Timed <TR>(TimeSpan span, ITransient trans)
        {
            var timed = TimedFuture <TR>(span);

            timed.TimedOut += (tr) => trans.Complete();
            return(Prepare(timed));
        }
Exemplo n.º 2
0
 private void Elapsed(ITransient tr)
 {
     Timer.Elapsed -= Elapsed;
     HasTimedOut    = true;
     TimedOut?.Invoke(this);
     Complete();
 }
Exemplo n.º 3
0
        public IGenerator ResumeAfter(ITransient other)
        {
            //Verbosity = 100;
            if (IsNullOrInactive(other))
            {
                Verbose(10, $"<color=blue>Gen: </color><b>{other.Name}</b> already complete, resuming <b>{Name}</b>.");
                Resume();
                return(this);
            }

            Verbose(10, $"<color=blue>Gen: </color>Suspending <b>{Name}</b> until after <b>{other.Name}</b>.");
            Suspend();

            // thanks to https://github.com/innostory for reporting an issue
            // where a dangling reference to 'other' resulted in memory leaks.
            void OnCompleted(ITransient tr)
            {
                other.Completed -= OnCompleted;
                Verbose(10, $"<color=blue>Gen: </color><b>{other.Name}</b> completed, resuming <b>{Name}</b>.");
                Resume();
            }

            other.Completed += OnCompleted;

            return(this);
        }
Exemplo n.º 4
0
        public HomeModule(ITransient transient, IRequestScoped requestScoped)
            : base("/home")
        {
            _transient = transient;
            _requestScoped = requestScoped;
            Debug.Assert(_requestScoped == _transient.RequestScoped);

            Get["/"] = _ =>
            {
                var viewBag = new DynamicDictionary();
                viewBag.Add("Transient", _transient);
                viewBag.Add("RequestScoped", _requestScoped);
                return View["home/index", viewBag];
            };

            Get["/index", runAsync: true] = async (_, token) =>
            {
                await Task.Delay(1000);
                return "123";
            };

            Get["/list", runAsync: true] = async (_, token) =>
            {
                await Task.Delay(1);
                return 500;
            };

            Get["/edit", runAsync: true] = async (_, token) =>
            {
                await Task.Delay(1);
                return 404;
            };
        }
Exemplo n.º 5
0
        public HomeModule(ITransient transient, IRequestScoped requestScoped) : base("/home")
        {
            _transient     = transient;
            _requestScoped = requestScoped;
            Debug.Assert(_requestScoped == _transient.RequestScoped);

            Get["/"] = _ =>
            {
                var viewBag = new DynamicDictionary();
                viewBag.Add("Transient", _transient);
                viewBag.Add("RequestScoped", _requestScoped);
                return(View["home/index", viewBag]);
            };

            Get["/index", runAsync : true] = async(_, token) =>
            {
                await Task.Delay(1000);

                return("123");
            };

            Get["/list", runAsync : true] = async(_, token) =>
            {
                await Task.Delay(1);

                return(500);
            };

            Get["/edit", runAsync : true] = async(_, token) =>
            {
                await Task.Delay(1);

                return(404);
            };
        }
Exemplo n.º 6
0
        public void ScopedDependencyFromTransientNotSharedAcrossScopes()
        {
            // Arrange
            var collection = new TestServiceCollection()
                             .AddTransient <ITransient, Transient>()
                             .AddScoped <IScoped, Scoped>();

            var provider = collection.BuildServiceProvider();

            // Act
            ITransient transient1a = null;
            ITransient transient1b = null;
            ITransient transient2b = null;

            using (var scope1 = provider.CreateScope())
            {
                transient1a = scope1.ServiceProvider.GetService <ITransient>();
            }

            using (var scope2 = provider.CreateScope())
            {
                transient1b = scope2.ServiceProvider.GetService <ITransient>();
                transient2b = scope2.ServiceProvider.GetService <ITransient>();
            }

            // Assert
            Assert.NotSame(transient1a, transient1b);
            Assert.NotSame(transient1b, transient2b);
            Assert.NotSame(transient1a.ScopedDependency, transient1b.ScopedDependency);
            Assert.Same(transient1b.ScopedDependency, transient2b.ScopedDependency);
        }
Exemplo n.º 7
0
 public ScopesController(IServiceOne testingServiceOne, IServiceTwo testingServiceTwo, ISingleton singleton, IScoped scoped, ITransient transient)
 {
     this.testingServiceOne = testingServiceOne;
     this.testingServiceTwo = testingServiceTwo;
     this.singleton         = singleton;
     this.scoped            = scoped;
     this.transient         = transient;
 }
Exemplo n.º 8
0
 public Task Invoke(HttpContext httpContext, ITransient transient, IScope scope, ISingleton singleton)
 {
     transient.Count++;
     scope.Count++;
     singleton.Count++;
     //await httpContext.Response.WriteAsync(string.Format("transient:\t{0},scope:\t{1},singleton:\t{2}", transient.Count, scope.Count, singleton.Count));
     return(_next(httpContext));
 }
Exemplo n.º 9
0
        private void Trip(IGroup self, ITransient other)
        {
            Reason = other;

            Tripped?.Invoke(this, other);

            Complete();
        }
Exemplo n.º 10
0
 public SomeController(ITransient transient, IScoped scoped, ISingleton singleton,
                       Func <ITransient> transientFactory)
 {
     Transient        = transient;
     Scoped           = scoped;
     Singleton        = singleton;
     TransientFactory = transientFactory;
 }
Exemplo n.º 11
0
 public GenerateController(
     ITransient transient,
     IScoped scoped,
     ISingleton singleton)
 {
     _transient = transient;
     _scoped    = scoped;
     _singleton = singleton;
 }
Exemplo n.º 12
0
 public HomeController(ITransient transientService1, ITransient transientService2, ISingleton singletonService1, ISingleton singletonService2, IScoped scopedService1, IScoped scopedService2)
 {
     this.transientService1 = transientService1;
     this.transientService2 = transientService2;
     this.singletonService1 = singletonService1;
     this.singletonService2 = singletonService2;
     this.scopedService1    = scopedService1;
     this.scopedService2    = scopedService2;
 }
Exemplo n.º 13
0
        private void Trip(IGroup self, ITransient other)
        {
            Reason = other;

            if (Tripped != null)
                Tripped(this, other);

            Complete();
        }
Exemplo n.º 14
0
 public TestController(ITransient injectedTransientItem, ISingleton injectedSingletonItem, IScoped injectedScopedItem, ILogger <TestController> injectedLogger)
 {
     _theTransient = injectedTransientItem;
     _theSingleton = injectedSingletonItem;
     _theScoped    = injectedScopedItem;
     _theLogger    = injectedLogger;
     _theLogger.LogDebug($"The TestController that was created");
     _theLogger.LogDebug($"The Transient that was injected has data: {injectedTransientItem.Data}");
 }
Exemplo n.º 15
0
 public SampleService(IFoo foo, IBar bar, ISingleton singleton, ITransient transient, IAsyncClass asyncClass)
 {
     _id         = Guid.NewGuid();
     _foo        = foo ?? throw new ArgumentNullException(nameof(foo));
     _bar        = bar ?? throw new ArgumentNullException(nameof(bar));
     _singleton  = singleton ?? throw new ArgumentNullException(nameof(singleton));
     _transient  = transient ?? throw new ArgumentNullException(nameof(transient));
     _asyncClass = asyncClass ?? throw new ArgumentNullException(nameof(asyncClass));
 }
Exemplo n.º 16
0
 public HomeController(ICalculator calc,
                       IScoped scoped1,
                       IScoped scoped2,
                       ITransient transient1,
                       ITransient transient2)
 {
     _Calculator      = calc;
     _ScopedEqual     = scoped1 == scoped2;
     _TransientsEqual = transient1 == transient2;
 }
Exemplo n.º 17
0
        protected void DeferAdd(ITransient other)
        {
            if (other == null)
            {
                return;
            }

            _Deletions.RemoveRef(other);
            _Additions.Add(other);
        }
Exemplo n.º 18
0
        public void Remove(ITransient other)
        {
            if (other == null)
            {
                return;
            }

            Additions.RemoveRef(other);
            Deletions.Add(other);
        }
Exemplo n.º 19
0
 public HomeController(ICalculator calc, 
     IScoped scoped1,
     IScoped scoped2,
     ITransient transient1,
     ITransient transient2)
 {
     _Calculator = calc;
     _ScopedEqual = scoped1 == scoped2;
     _TransientsEqual = transient1 == transient2;
 }
Exemplo n.º 20
0
        private int Print(ITransient trans, int level)
        {
            if (trans == null)
            {
                return(level);
            }

            Lead(level);
            Header(trans);
            return(!(trans is IGroup @group) ? level : Contents(group, level + 1));
        }
Exemplo n.º 21
0
        private void CompletedBecause(ITransient other)
        {
            if (!Active)
            {
                return;
            }

            WhyCompleted?.Invoke(this, other);

            Complete();
        }
Exemplo n.º 22
0
        public async Task Invoke(HttpContext httpContext, ITransient transient, IScope scope, ISingleton singleton, INameService nameService)
        {
            var name = await nameService.HelloAsync("tim");

            transient.Count++;
            scope.Count++;
            singleton.Count++;
            await httpContext.Response.WriteAsync(string.Format("transient:\t{0},scope:\t{1},singleton:\t{2}", transient.Count, scope.Count, singleton.Count));

            //return _next(httpContext);
        }
        public ProductController(ITransient transient1, ITransient transient2, ISingleton singleton1, ISingleton singleton2, IScoped scoped1, IScoped scoped2)
        {
            _transient1 = transient1;
            _transient2 = transient2;

            _singleton1 = singleton1;
            _singleton2 = singleton2;

            _scoped1 = scoped1;
            _scoped2 = scoped2;
        }
Exemplo n.º 24
0
        private void Trip(IGroup self, ITransient other)
        {
            Reason = other;

            if (Tripped != null)
            {
                Tripped(this, other);
            }

            Complete();
        }
Exemplo n.º 25
0
        /// <inheritdoc />
        public void SuspendAfter(ITransient other)
        {
            if (IsNullOrEmpty(other))
            {
                Suspend();
                return;
            }

            Resume();

            other.Completed += tr => Suspend();
        }
Exemplo n.º 26
0
        /// <inheritdoc />
        public void Remove(ITransient other)
        {
            if (other == null)
            {
                return;
            }

            //if (!Contents.ContainsRef(other) || Deletions.ContainsRef(other))
            //	return;

            Additions.RemoveRef(other);
            Deletions.Add(other);
        }
Exemplo n.º 27
0
        private int Print(ITransient trans, int level)
        {
            if (trans == null)
            {
                return(level);
            }

            Lead(level);
            Header(trans);
            var group = trans as IGroup;

            return(group == null ? level : Contents(group, level + 1));
        }
Exemplo n.º 28
0
        private void HandleElapsed(ITransient sender)
        {
            if (!Active)
            {
                return;
            }

            TimedOut?.Invoke(this);

            HasTimedOut = true;

            Complete();
        }
Exemplo n.º 29
0
        public Combined(ISingleton first, ITransient second)
        {
            if (first == null)
            {
                throw new ArgumentNullException("first");
            }

            if (second == null)
            {
                throw new ArgumentNullException("second");
            }

            Instances++;
        }
Exemplo n.º 30
0
        private void CompletedBecause(ITransient other)
        {
            if (!Active)
            {
                return;
            }

            if (WhyCompleted != null)
            {
                WhyCompleted(this, other);
            }

            Complete();
        }
Exemplo n.º 31
0
        public Combined(ISingleton first, ITransient second)
        {
            if (first == null)
            {
                throw new ArgumentNullException("first");
            }

            if (second == null)
            {
                throw new ArgumentNullException("second");
            }

            Instances++;
        }
Exemplo n.º 32
0
        /// <inheritdoc />
        public bool ResumeAfter(ITransient other)
        {
            if (IsNullOrEmpty(other))
            {
                Resume();
                return true;
            }

            Suspend();

            other.Completed += tr => Resume();

            return true;
        }
Exemplo n.º 33
0
        /// <inheritdoc />
        public bool ResumeAfter(ITransient other)
        {
            if (IsNullOrEmpty(other))
            {
                Resume();
                return(true);
            }

            Suspend();

            other.Completed += tr => Resume();

            return(true);
        }
        public Combined(ISingleton stateless, ITransient stateful)
        {
            if (stateless == null)
            {
                throw new ArgumentNullException(nameof(stateless));
            }

            if (stateful == null)
            {
                throw new ArgumentNullException(nameof(stateful));
            }

            _singleton = stateless;
            _transient = stateful;
        }
 public TestController(
     IScoped scoped,
     IScoped scoped2,
     ITransient transient,
     ITransient transient2,
     ISingleton singleton,
     ISingleton singleton2)
 {
     _singleton  = singleton;
     _singleton2 = singleton2;
     _transient  = transient;
     _transient2 = transient2;
     _scoped     = scoped;
     _scoped2    = scoped2;
 }
Exemplo n.º 36
0
		/// <inheritdoc />
		public void CompleteAfter(ITransient other)
		{
			if (!Active)
				return;

			if (other == null)
				return;

			if (!other.Active)
			{
				Complete();
				return;
			}

			other.Completed += tr => CompletedBecause(other);
		}
Exemplo n.º 37
0
        public ScopedCombined(ITransient transient, ISingleton singleton)
        {
            if (transient == null)
            {
                throw new ArgumentNullException("transient");
            }

            if (singleton == null)
            {
                throw new ArgumentNullException("singleton");
            }

            if (!(transient is ScopedTransient))
            {
                throw new ArgumentException("transient should be of type ScopedTransient");
            }

            Instances++;
        }
Exemplo n.º 38
0
 /// <summary>
 /// Return true if the given other transient is either null or does not exist
 /// </summary>
 /// <returns>
 /// True if the given other transient is either null or does not exist
 /// </returns>
 /// <param name='other'>
 /// The transient to consider
 /// </param>
 public static bool IsNullOrEmpty(ITransient other)
 {
     return other == null || !other.Active;
 }
Exemplo n.º 39
0
        void CompletedBecause(ITransient other)
        {
            if (!Active)
                return;

            if (WhyCompleted != null)
                WhyCompleted(this, other);

            Complete();
        }
Exemplo n.º 40
0
        /// <inheritdoc />
        public void SuspendAfter(ITransient other)
        {
            if (IsNullOrEmpty(other))
            {
                Suspend();
                return;
            }

            Resume();

            other.Completed += tr => Suspend();
        }
Exemplo n.º 41
0
 public Thing(ITransient transient, ISingletonThing singletonThing)
 {
     _transient = transient;
     _singletonThing = singletonThing;
 }
Exemplo n.º 42
0
 public SingletonThing(ITransient transient)
 {
     _transient = transient;
 }
Exemplo n.º 43
0
 public Thing(ITransient transient, ISingleton singleton)
 {
     _transient = transient;
     _singleton = singleton;
 }
Exemplo n.º 44
0
 public SampleModuleWithTransientDependency(ITransient transient)
 {
     Transient = transient;
 }