public void TestInitialize() { _context = new ComponentContext(); _context.Register(typeof(InterfaceContractComponent)); _context.Register(typeof(AbstractContractComponent)); _context.Register(typeof(ConcreteContractComponent)); }
public void RegistrationOrderInsensitivity() { var contextOne = new ComponentContext(); contextOne.Register(typeof(EmptyComponentAndContract)); contextOne.Register(typeof(ComponentWithFieldPlug)); contextOne.Register(typeof(ComponentWithPropertyPlug)); var contextTwo = new ComponentContext(); contextTwo.Register(typeof(ComponentWithFieldPlug)); contextTwo.Register(typeof(ComponentWithPropertyPlug)); contextTwo.Register(typeof(EmptyComponentAndContract)); var cField = contextOne.GetComponent <ComponentWithFieldPlug>(); var cProperty = contextOne.GetComponent <ComponentWithPropertyPlug>(); Assert.IsNotNull(cField); Assert.IsNotNull(cProperty); Assert.IsNotNull(cField.Plug); Assert.IsNotNull(cProperty.Plug); Assert.AreSame(cField.Plug, cProperty.Plug); cField = contextTwo.GetComponent <ComponentWithFieldPlug>(); cProperty = contextTwo.GetComponent <ComponentWithPropertyPlug>(); Assert.IsNotNull(cField); Assert.IsNotNull(cProperty); Assert.IsNotNull(cField.Plug); Assert.IsNotNull(cProperty.Plug); Assert.AreSame(cField.Plug, cProperty.Plug); }
public void Initialize() { _context = new ComponentContext(); _context.Register(typeof(EmptyComponentAndContract)); _context.Register(typeof(ComponentWithFieldPlug)); _context.Register(typeof(ComponentWithPropertyPlug)); }
public void ResourcePlugAsField() { _context.Register(typeof(WithFieldResourcePlug)); var c = _context.GetComponent <WithFieldResourcePlug>(); Assert.IsNotNull(c.ResourcePlug); }
public void ConfigurationPointAsField() { _context.Register(typeof(WithFieldConfigurationPoint)); var c = _context.GetComponent <WithFieldConfigurationPoint>(); Assert.AreEqual(c.SomeConfigurationPoint, "SomeConfigurationValue"); }
public void ComponentPlugAsField() { _context.Register(typeof(WithFieldComponentPlug)); var c = _context.GetComponent <WithFieldComponentPlug>(); Assert.IsNotNull(c.SampleContract); }
public void RegisterSingleProvided() { _context.Register(typeof(ComponentOne)); var c = _context.GetComponent <IContractOne>(); Assert.IsNotNull(c); }
public void SelfContractWithoutExplicitContractRegistrationTest() { _context.Register(typeof(SelfContractComponent)); var c = _context.GetComponent <SelfContractComponent>(); Assert.IsNotNull(c); }
public void NoAttributesAtAll() { _context.Configuration.DisableAttributeChecking = true; _context.Register(typeof(INonAttributedContractOne), typeof(NonAttributedComponentOne)); var c = _context.GetComponent <INonAttributedContractOne>(); Assert.IsNotNull(c); }
public void OptConfigNotProvided() { _context.Register(typeof(ComponentWithOptionalConfig)); var c = _context.GetComponent <ComponentWithOptionalConfig>(); Assert.IsNotNull(c); Assert.IsNull(c.SomeConfig); }
public void TestInitialize() { _context = new ComponentContext(); _context.Configuration.DisableAttributeChecking = true; _context.Register(typeof(ComponentOne)); _context.Register(typeof(ComponentTwo)); _context.Register(typeof(IComponentOne), "name", typeof(ComponentOne)); _context.Register(typeof(IComponentTwo), "name", typeof(ComponentTwo)); }
public void GenericGetComponentWithoutName() { var cLazy = _context.LazyGetComponent <ISampleContract>(); _context.Register(typeof(SampleComponent)); var c = cLazy.Value; Assert.IsNotNull(c); }
public void TestInitialize() { _context = new ComponentContext(); _context.Configuration.DisableAttributeChecking = true; _context.Register(typeof(ComponentOne)); _context.Register(typeof(IComponentTwo), "name", typeof(ComponentTwo)); _context.SetVariableValue("one", "someString"); _context.SetVariableValue("two", 5); }
public void AttributeRefWithoutName() { _context.Register(typeof(SampleComponent)); _context.ProcessCompositionXmlFromResource("Appson.Composer.UnitTests.XmlValueParser.Xmls.AOtherSimple.xml"); var o = _context.GetVariable("refWithoutName"); Assert.IsNotNull(o); Assert.IsInstanceOfType(o, typeof(ISampleContract)); }
static void Main() { var composer = new ComponentContext(); composer.Register(typeof(ConsoleLogger)); composer.Register(typeof(DefaultCustomerData)); composer.Register(typeof(DefaultOrderData)); composer.Register(typeof(DefaultOrderLogic)); composer.GetComponent <IOrderLogic>().PlaceOrder("John", 17); }
public void GenericGetComponentFamily() { var cLazy = _context.LazyGetComponentFamily <ISampleContract>(); _context.Register(typeof(SampleComponent)); var c = cLazy.Value; Assert.IsNotNull(c); Assert.AreEqual(1, c.Count()); }
public void ComponentWithClosedGenericParams() { _context.Register(typeof(ClosedComponentOne)); var c1 = _context.GetComponent <IGenericContractOne <string> >(); var c2 = _context.GetComponent <IGenericContractOne <int> >(); var c3 = _context.GetComponent <IGenericContractTwo <int, string> >(); Assert.IsNotNull(c1); Assert.IsNull(c2); Assert.IsNull(c3); }
public void DefaultConstructorFromMany() { _context.Register(typeof(MultiConstructorsWithDefault)); var c = _context.GetComponent <MultiConstructorsWithDefault>(); Assert.IsNotNull(c); Assert.AreEqual(1, c.InvokedConstructor); Assert.IsNull(c.A); Assert.IsNull(c.B); }
public void RegisterTwoTimesQueryBySelf() { _context.Register(typeof(ContractAgnosticComponent)); var all = _context.GetAllComponents <ContractAgnosticComponent>(); Assert.IsNotNull(all); Assert.IsTrue(all.Count() == 2); var allArray = all.ToArray(); var c0 = allArray[0]; var c1 = allArray[1]; Assert.AreNotSame(c0, c1); }
public void RegisterTwoTimesQueryBySelf() { _context.Register(typeof(DefaultCacheComponent)); // Register for second time var all = _context.GetAllComponents <DefaultCacheComponent>(); Assert.IsNotNull(all); Assert.IsTrue(all.Count() == 2); var allArray = all.ToArray(); var c0 = allArray[0]; var c1 = allArray[1]; Assert.AreNotSame(c0, c1); }
static void Main() { var context = new ComponentContext(); context.ProcessCompositionXmlFromResource("Compositional.Composer.Samples.Basic.CalculatorComposition.xml"); var classEmitter = context.GetComponent <IClassEmitter>(); IEmittedTypeHandler emittedTypeHandler = new TestEmittedTypeHandler(); context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IAdder)))); context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IMultiplier)))); context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IDivider)))); context.GetComponent <IProgramRunner>().Run(); }
public void RegisterJobProcessor(Expression <Func <object> > processorInstanceProvider, Type stepType) { var contract = typeof(IJobProcessor <>).MakeGenericType(stepType); bool isTypeCorrect; if (processorInstanceProvider.Body.Type.IsInterface) { isTypeCorrect = processorInstanceProvider .Body .Type .GetGenericTypeDefinition() .IsAssignableFrom(typeof(IJobProcessor <>)); } else { isTypeCorrect = processorInstanceProvider .Body .Type .GetInterfaces() .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IJobProcessor <>)); } if (!isTypeCorrect) { throw new ArgumentException("Processor should implement IJobProcessor<>"); } ComponentContext.Register(contract, new ExternalProviderComponentFactory(processorInstanceProvider.Compile())); }
public void CountEventsGetShared() { _context.Register(typeof(SharedComponent)); var listener = new CountingCompositionListener(); _context.RegisterCompositionListener("counter", listener); _context.GetComponent <ISampleContract>(); _context.GetComponent <ISampleContract>(); _context.GetComponent <ISampleContract>(); Assert.AreEqual(1, listener.OnComponentCreatedCount); Assert.AreEqual(1, listener.OnComponentComposedCount); Assert.AreEqual(3, listener.OnComponentRetrievedCount); }
private static void ExtractAllComponents(Assembly assembly, ComponentContext context) { Type[] types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException rtle) { var message = "Could not load types of assembly '" + assembly.FullName + "', with the following messages: \n"; message = rtle.LoaderExceptions.Aggregate(message, (current, exception) => current + (exception.Message + "\n")); throw new CompositionException(message); } var candidateTypes = types .Where(ComponentContextUtils.HasComponentAttribute) .Where(componentType => !ComponentContextUtils.HasIgnoredOnAssemblyRegistrationAttribute(componentType)); foreach (var componentType in candidateTypes) { context.Register(componentType); } }
public void GetComponentWithoutRegistrationThrows() { _context = new ComponentContext(); _context.Register(typeof(ComponentWithFieldPlug)); _context.GetComponent <ComponentWithFieldPlug>(); }
static void Main() { var composer = new ComponentContext(); composer.Register(typeof(DefaultLogger)); composer.GetComponent <ILogger>().Log("Hello, compositional world!"); }
static void Main() { var context = new ComponentContext(); context.ProcessCompositionXmlFromResource("Compositional.Composer.Samples.Basic.CalculatorComposition.xml"); context.Register(new CalculatorFactory()); context.GetComponent <IProgramRunner>().Run(); }
public void TestInitialize() { _context = new ComponentContext(); _context.Register(typeof(SampleComponentOne)); _listener = new ParameterRecorderListener(); _context.RegisterCompositionListener("recorder", _listener); _context.GetComponent <ISampleContract>(); }
static void Main() { // Create a new component context. var context = new ComponentContext(); // Register the types into the context individually. context.Register(typeof(DefaultCalculator)); // The following component registrations is not referenced // directly from the main method, but is injected into the // plugs of DefaultCalculator. context.Register(typeof(DefaultAdder)); context.Register(typeof(DefaultMultiplier)); context.Register(typeof(DefaultDivider)); // When calling GetComponent, Composer will instantiate // the components and fill the plugs recursively until // the component graph is completely initialized. var calculator = context.GetComponent <ICalculator>(); Console.WriteLine(); // Calling methods of ICalculator, which is realized by // DefaultCalculator class. Console.WriteLine("67 + 12 = {0}", calculator.Add(67, 12)); Console.WriteLine(); Console.WriteLine("67 - 12 = {0}", calculator.Subtract(67, 12)); Console.WriteLine(); Console.WriteLine("67 * 12 = {0}", calculator.Multiply(67, 12)); Console.WriteLine(); Console.WriteLine("67 / 12 = {0} (with remainder = {1})", calculator.Divide(67, 12), calculator.Remainder(67, 12)); Console.WriteLine(); }
private void ConfigureComposer() { var context = new ComponentContext(); var assembly = Assembly.Load("Nebula"); context.RegisterAssembly(assembly); context.Register(typeof(NebulaContext), new PreInitializedComponentFactory(this)); context.Configuration.DisableAttributeChecking = true; ComponentContext = context; }