public DisposableSpamService(DefaultMailSenderService mailSender, DisposableTemplateEngine templateEngine, PoolableComponent1 pool) { this.mailSender = mailSender; this.templateEngine = templateEngine; this.pool = pool; }
public void SimpleUsage() { IKernel kernel = new DefaultKernel(); kernel.AddComponent("a", typeof(PoolableComponent1)); PoolableComponent1 inst1 = kernel["a"] as PoolableComponent1; PoolableComponent1 inst2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(inst1); Assert.IsNotNull(inst2); kernel.ReleaseComponent(inst2); kernel.ReleaseComponent(inst1); PoolableComponent1 other1 = kernel["a"] as PoolableComponent1; PoolableComponent1 other2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other1); Assert.IsNotNull(other2); Assert.AreSame(inst1, other1); Assert.AreSame(inst2, other2); kernel.ReleaseComponent(inst2); kernel.ReleaseComponent(inst1); }
public void MaxSize() { IKernel kernel = new DefaultKernel(); kernel.AddComponent("a", typeof(PoolableComponent1)); ArrayList instances = new ArrayList(); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); PoolableComponent1 other1 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other1); Assert.IsTrue(!instances.Contains(other1)); foreach (object inst in instances) { kernel.ReleaseComponent(inst); } kernel.ReleaseComponent(other1); PoolableComponent1 other2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other2); Assert.IsTrue(other1 != other2); Assert.IsTrue(instances.Contains(other2)); kernel.ReleaseComponent(other2); }
public void ExecuteMethodUntilSignal() { _startEvent.WaitOne(int.MaxValue, false); while (!_stopEvent.WaitOne(1, false)) { PoolableComponent1 instance = _kernel["a"] as PoolableComponent1; Assert.IsNotNull(instance); Thread.Sleep(1 * 500); _kernel.ReleaseComponent(instance); } }