public void DefaultUseCase() { // Arrange var container = new Container(); var factory = new KeyedFactory <string, IPlugin>(container, StringComparer.OrdinalIgnoreCase); // Act using (var keyedRegistar = factory.BeginRegistrations()) { keyedRegistar.Register <Plugin1>("foo"); keyedRegistar.Register <Plugin2>("bar", Lifestyle.Singleton); } IPlugin foo1 = factory["foo"]; IPlugin foo2 = factory["foo"]; IPlugin bar1 = factory["bar"]; IPlugin bar2 = factory["BAR"]; // Assert AssertThat.IsInstanceOfType(typeof(Plugin1), foo1); Assert.IsFalse(object.ReferenceEquals(foo1, foo2), "foo should be transient."); AssertThat.IsInstanceOfType(typeof(Plugin2), bar1); Assert.IsTrue(object.ReferenceEquals(bar1, bar2), "bar should be singleton."); }
public void TestFactorySpeed() { KeyedFactory<int, Product> factory = new KeyedFactory<int, Product>(); int key = 0; factory.RegisterType<Product>(key++); factory.RegisterMethod(key++, delegate { return Activator.CreateInstance<Product>(); }); factory.RegisterMethod(key++, delegate { return (Product) Activator.CreateInstance(typeof (Product));}) ; factory.RegisterMethod(key++, delegate { return new Product(); }); factory.RegisterImmutable(key++, new Product()); factory.RegisterPrototype(key++, new Product()); ConstructorInfo ci = typeof (Product).GetConstructor(Type.EmptyTypes); factory.RegisterMethod(key++, delegate { return (Product) ci.Invoke(null); }); foreach (int k in factory.Keys) factory.Create(k); int iterationCount = 1000000; foreach (int k in factory.Keys) { Stopwatch watch = Stopwatch.StartNew(); for (int i = 0; i < iterationCount; i++) factory.Create(k); Console.WriteLine("{0} {1}", k, watch.ElapsedMilliseconds); } }
public void TestFactorySpeed() { KeyedFactory <int, Product> factory = new KeyedFactory <int, Product>(); int key = 0; factory.RegisterType <Product>(key++); factory.RegisterMethod(key++, delegate { return(Activator.CreateInstance <Product>()); }); factory.RegisterMethod(key++, delegate { return((Product)Activator.CreateInstance(typeof(Product))); }); factory.RegisterMethod(key++, delegate { return(new Product()); }); factory.RegisterImmutable(key++, new Product()); factory.RegisterPrototype(key++, new Product()); ConstructorInfo ci = typeof(Product).GetConstructor(Type.EmptyTypes); factory.RegisterMethod(key++, delegate { return((Product)ci.Invoke(null)); }); foreach (int k in factory.Keys) { factory.Create(k); } int iterationCount = 1000000; foreach (int k in factory.Keys) { Stopwatch watch = Stopwatch.StartNew(); for (int i = 0; i < iterationCount; i++) { factory.Create(k); } Console.WriteLine("{0} {1}", k, watch.ElapsedMilliseconds); } }
public Scheduler(KeyedFactory <string, TTask> taskFactory) { Guard.ArgumentNotNull("taskFactory", taskFactory); _taskFactory = taskFactory; _eventQueue.EventOccurs += eventQueue_EventOccurs; }
public void DefaultUseCase() { // Arrange var container = new Container(); var factory = new KeyedFactory<string, IPlugin>(container, StringComparer.OrdinalIgnoreCase); // Act using (var keyedRegistar = factory.BeginRegistrations()) { keyedRegistar.Register<Plugin1>("foo"); keyedRegistar.Register<Plugin2>("bar", Lifestyle.Singleton); } IPlugin foo1 = factory["foo"]; IPlugin foo2 = factory["foo"]; IPlugin bar1 = factory["bar"]; IPlugin bar2 = factory["BAR"]; // Assert AssertThat.IsInstanceOfType(typeof(Plugin1), foo1); Assert.IsFalse(object.ReferenceEquals(foo1, foo2), "foo should be transient."); AssertThat.IsInstanceOfType(typeof(Plugin2), bar1); Assert.IsTrue(object.ReferenceEquals(bar1, bar2), "bar should be singleton."); }
public void TestFactory() { KeyedFactory<string, string> f = new KeyedFactory<string, string>(); f.RegisterImmutable("bla", "bla"); f.RegisterMethod("bla1", delegate { return "bla1"; }); Assert.AreEqual("bla", f.Create("bla")); Assert.AreEqual("bla1", f.Create("bla1")); }
private ContextControllerConditionNonHA ActivateTermination( EventBean triggeringEvent, object[] parentPartitionKeys, object partitionKey, IntSeqKey conditionPath, string optionalInitCondAsName) { ContextControllerConditionCallback callback = new ProxyContextControllerConditionCallback( ( conditionPathArg, originEndpoint, optionalTriggeringEvent, optionalTriggeringPattern, optionalTriggeringEventPattern, optionalPatternForInclusiveEval) => { var parentPath = conditionPathArg.RemoveFromEnd(); var getterKey = KeyedFactory.GetGetterKey(partitionKey); var removed = keyedSvc.KeyRemove(parentPath, getterKey); if (removed == null) { return; } // remember the terminating event, we don't want it to initiate a new partition LastTerminatingEvent = optionalTriggeringEvent != null ? optionalTriggeringEvent : optionalTriggeringEventPattern; realization.ContextPartitionTerminate( conditionPath.RemoveFromEnd(), removed.SubpathOrCPId, this, optionalTriggeringPattern, false, null); removed.TerminationCondition.Deactivate(); }); var partitionKeys = CollectionUtil.AddValue(parentPartitionKeys, partitionKey); var terminationCondition = ContextControllerConditionFactory.GetEndpoint( conditionPath, partitionKeys, KeyedFactory.keyedSpec.OptionalTermination, callback, this, false); ContextControllerEndConditionMatchEventProvider endConditionMatchEventProvider = null; if (optionalInitCondAsName != null) { endConditionMatchEventProvider = new ProxyContextControllerEndConditionMatchEventProvider( (map, triggeringEventArg) => ContextControllerKeyedUtil.PopulatePriorMatch(optionalInitCondAsName, map, triggeringEventArg), (map, triggeringPattern) => { }); } terminationCondition.Activate(triggeringEvent, endConditionMatchEventProvider, null); return terminationCondition; }
public void TestFactory() { KeyedFactory <string, string> f = new KeyedFactory <string, string>(); f.RegisterImmutable("bla", "bla"); f.RegisterMethod("bla1", delegate { return("bla1"); }); Assert.AreEqual("bla", f.Create("bla")); Assert.AreEqual("bla1", f.Create("bla1")); }
/// <summary> /// Initializes new instance of <see cref="ConfigBuilder"/>. /// </summary> public ConfigBuilder() { _mappingSourceBuilders = new KeyedFactory <Type, Mappings.Mappings, IMappingSource>(); _converterRegistrators = new Queue <Action <FieldConverterContainer> >(); }
/// <summary> /// Initializes a new instance of the <see cref="FieldConverterContainer"/> class. /// </summary> public FieldConverterContainer() { _fieldTypesMap = new Container <string, Type>(); _fieldConvertersBuilders = new KeyedFactory <Type, IFieldConverter>(); }