public IFuture <TR> Timed <TR>(TimeSpan span, ITransient trans) { var timed = TimedFuture <TR>(span); timed.TimedOut += (tr) => trans.Complete(); return(Prepare(timed)); }
private void Elapsed(ITransient tr) { Timer.Elapsed -= Elapsed; HasTimedOut = true; TimedOut?.Invoke(this); Complete(); }
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); }
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; }; }
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); }; }
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); }
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; }
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)); }
private void Trip(IGroup self, ITransient other) { Reason = other; Tripped?.Invoke(this, other); Complete(); }
public SomeController(ITransient transient, IScoped scoped, ISingleton singleton, Func <ITransient> transientFactory) { Transient = transient; Scoped = scoped; Singleton = singleton; TransientFactory = transientFactory; }
public GenerateController( ITransient transient, IScoped scoped, ISingleton singleton) { _transient = transient; _scoped = scoped; _singleton = singleton; }
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; }
private void Trip(IGroup self, ITransient other) { Reason = other; if (Tripped != null) Tripped(this, other); Complete(); }
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}"); }
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)); }
public HomeController(ICalculator calc, IScoped scoped1, IScoped scoped2, ITransient transient1, ITransient transient2) { _Calculator = calc; _ScopedEqual = scoped1 == scoped2; _TransientsEqual = transient1 == transient2; }
protected void DeferAdd(ITransient other) { if (other == null) { return; } _Deletions.RemoveRef(other); _Additions.Add(other); }
public void Remove(ITransient other) { if (other == null) { return; } Additions.RemoveRef(other); Deletions.Add(other); }
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)); }
private void CompletedBecause(ITransient other) { if (!Active) { return; } WhyCompleted?.Invoke(this, other); Complete(); }
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; }
private void Trip(IGroup self, ITransient other) { Reason = other; if (Tripped != null) { Tripped(this, other); } Complete(); }
/// <inheritdoc /> public void SuspendAfter(ITransient other) { if (IsNullOrEmpty(other)) { Suspend(); return; } Resume(); other.Completed += tr => Suspend(); }
/// <inheritdoc /> public void Remove(ITransient other) { if (other == null) { return; } //if (!Contents.ContainsRef(other) || Deletions.ContainsRef(other)) // return; Additions.RemoveRef(other); Deletions.Add(other); }
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)); }
private void HandleElapsed(ITransient sender) { if (!Active) { return; } TimedOut?.Invoke(this); HasTimedOut = true; Complete(); }
public Combined(ISingleton first, ITransient second) { if (first == null) { throw new ArgumentNullException("first"); } if (second == null) { throw new ArgumentNullException("second"); } Instances++; }
private void CompletedBecause(ITransient other) { if (!Active) { return; } if (WhyCompleted != null) { WhyCompleted(this, other); } Complete(); }
/// <inheritdoc /> public bool ResumeAfter(ITransient other) { if (IsNullOrEmpty(other)) { Resume(); return true; } Suspend(); other.Completed += tr => Resume(); return true; }
/// <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; }
/// <inheritdoc /> public void CompleteAfter(ITransient other) { if (!Active) return; if (other == null) return; if (!other.Active) { Complete(); return; } other.Completed += tr => CompletedBecause(other); }
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++; }
/// <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; }
void CompletedBecause(ITransient other) { if (!Active) return; if (WhyCompleted != null) WhyCompleted(this, other); Complete(); }
public Thing(ITransient transient, ISingletonThing singletonThing) { _transient = transient; _singletonThing = singletonThing; }
public SingletonThing(ITransient transient) { _transient = transient; }
public Thing(ITransient transient, ISingleton singleton) { _transient = transient; _singleton = singleton; }
public SampleModuleWithTransientDependency(ITransient transient) { Transient = transient; }