public ObjectDef AddType(Type type) { var objectDef = new ObjectDef(type); Items.Add(objectDef); return objectDef; }
protected override void configureObject(ObjectDef def) { def.DependencyByValue(new ViewPath { ViewName = _viewName }); }
protected override ObjectDef buildObjectDef() { var def = new ObjectDef(typeof (TopicBehavior)); def.DependencyByValue(_topic); return def; }
public void ReadObjectOffImages(XmlNode objectNode, ref ObjectDef def) { XmlNodeList offImageNodes = objectNode.SelectNodes(".//image_off"); foreach (XmlNode offImageNode in offImageNodes) { string name = offImageNode.InnerText; int slot = 0; if (offImageNode.Attributes["slot"] != null) { slot = int.Parse(offImageNode.Attributes["slot"].Value); } Image img = new Image(); BitmapImage bitImg = new BitmapImage(); bitImg.BeginInit(); var path = Path.Combine(Environment.CurrentDirectory + name); bitImg.UriSource = new Uri(path); bitImg.EndInit(); img.Source = bitImg; img.Width = winCellSize; img.Height = winCellSize; img.Stretch = Stretch.Uniform; img.Margin = new Thickness(0); RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor); if (img.Source != null) { def.offImageList.Add(img); } } }
public static void ConfigureDeleteCommand(ObjectDef m, string schemaName, SqlCommand cmd, IEnumerable <object> values = null) { cmd.CommandType = CommandType.Text; string entityName = m.EntityName; StringBuilder sb = new StringBuilder(); sb.AppendLine("DELETE "); sb.AppendLine(string.Format("FROM [{0}].[{1}]", schemaName, entityName)); var qProps = (from mp in m.Properties //join mep in m.ModelEntityMappings on mp.Name equals mep.ModelPropertyName //where mp.IsKey.GetValueOrDefault() orderby mp.PropertyOrder select new { Name = mp.ColumnName, IsKey = mp.IsKey }); for (int i = 0; i < qProps.Count(); i++) { if (qProps.ElementAt(i).IsKey) { sb.AppendLine(string.Format("WHERE [{0}] = @{0}", qProps.ElementAt(i).Name)); if (values != null) { cmd.Parameters.AddWithValue("@" + qProps.ElementAt(i).Name, values.ElementAt(i) != null ? values.ElementAt(i) : DBNull.Value); } } } cmd.CommandText = sb.ToString(); }
protected override void Read(NReader rdr) { Tiles = new TileData[rdr.ReadInt16()]; for (var i = 0; i < Tiles.Length; i++) { Tiles[i] = new TileData() { X = rdr.ReadInt16(), Y = rdr.ReadInt16(), Tile = (Tile)rdr.ReadUInt16(), }; } NewObjs = new ObjectDef[rdr.ReadInt16()]; for (var i = 0; i < NewObjs.Length; i++) { NewObjs[i] = ObjectDef.Read(rdr); } Drops = new int[rdr.ReadInt16()]; for (var i = 0; i < Drops.Length; i++) { Drops[i] = rdr.ReadInt32(); } }
protected override void configure(ObjectDef def) { if (_membershipType != null) { def.DependencyByType <IMembershipRepository>(new ObjectDef(_membershipType)); } }
public ObjectDef SetServiceIfNone(Type interfaceType, Type concreteType) { var objectDef = new ObjectDef(concreteType); fill(interfaceType, objectDef); return(objectDef); }
private static ComponentRegistration map(Type serviceType, ObjectDef def, bool isDefault) { var c = Component.For(serviceType); if (def.Value != null) { c.Instance(def.Value); } else { c.ImplementedBy(def.Type); } if (isDefault) { c.IsDefault().LifestyleScoped(); } else { c.Named(def.Name).IsFallback(); if (def.IsSingleton) { c.LifestyleSingleton(); } else { c.LifestyleScoped(); } } return(c); }
/// <summary> /// Makes the behavior execute only if the condition against a model /// object pulled from IFubuRequest is true /// </summary> public void ConditionByModel <T>(Func <T, bool> filter) where T : class { var description = "By Model: Func<{0}, bool>".ToFormat(typeof(T).Name); Trace(new ConditionAdded(description)); _conditionalDef = ConditionalObjectDef.ForModel(filter); }
protected override ObjectDef buildObjectDef() { var def = new ObjectDef(typeof(OptionalAssetsBehavior)); def.DependencyByValue(_assetName); return(def); }
protected override ObjectDef buildObjectDef() { var def = new ObjectDef(typeof (ChromeBehavior<>), _contentType); def.DependencyByValue<Action<ChromeContent>>(content => content.Title = Title()); return def; }
public BottleConfigurationDef(string provenance) { _objectDef = new ObjectDef(typeof(AssertBottleConfiguration)); _objectDef.DependencyByValue(provenance); _rules = _objectDef.EnumerableDependenciesOf <IBottleConfigurationRule>(); }
public void build_an_object_with_dependencies() { var request = new InMemoryFubuRequest(); var def = new ObjectDef(typeof (FakeJsonBehavior)); def.DependencyByValue(typeof (IFubuRequest), request); var jsonWriter = def.DependencyByType(typeof (IJsonWriter), typeof (AjaxAwareJsonWriter)); jsonWriter.DependencyByType(typeof (IOutputWriter), typeof (OutputWriter)); jsonWriter.DependencyByType(typeof(IRequestData), typeof(InMemoryRequestData)); def.DependencyByType(typeof (IRequestData), typeof (InMemoryRequestData)); var container = new Container(x => { x.For<IFileSystem>().Use<FileSystem>(); x.For<IHttpWriter>().Use<NulloHttpWriter>(); x.For<IActionBehavior>().UseInstance(new ObjectDefInstance(def)); x.For<ILogger>().Use<Logger>(); x.For<ISystemTime>().Use(() => SystemTime.Default()); }); var jsonBehavior = container.GetInstance<IActionBehavior>().ShouldBeOfType<FakeJsonBehavior>(); jsonBehavior.Writer.ShouldBeOfType<AjaxAwareJsonWriter>(); jsonBehavior.Request.ShouldBeTheSameAs(request); }
private void bakeBehaviorGraphIntoContainer(BehaviorGraph graph, IContainerFacility containerFacility) { graph.As <IRegisterable>().Register(_registry.Value.DiagnosticLevel, containerFacility.Register); // Important to register itself containerFacility.Register(typeof(IContainerFacility), ObjectDef.ForValue(containerFacility)); }
protected override void Read(NReader rdr) { Tiles = new TileData[rdr.ReadInt16()]; for (int i = 0; i < Tiles.Length; i++) { Tiles[i] = new TileData { X = rdr.ReadInt16(), Y = rdr.ReadInt16(), Tile = rdr.ReadUInt16() }; } NewObjects = new ObjectDef[rdr.ReadInt16()]; for (int i = 0; i < NewObjects.Length; i++) { NewObjects[i] = ObjectDef.Read(rdr); } RemovedObjectIds = new int[rdr.ReadInt16()]; for (int i = 0; i < RemovedObjectIds.Length; i++) { RemovedObjectIds[i] = rdr.ReadInt32(); } }
static Attribute[] GetCustomAttributes(ObjectDef def) { var list = new List <Attribute>(); if (def.Interface != null && !string.IsNullOrEmpty(def.Interface.Name)) { list.Add(new CategoryAttribute(def.Interface.Name)); } else if (!string.IsNullOrEmpty(def.PropertyDef.Category)) { list.Add(new CategoryAttribute(def.PropertyDef.Category)); } if (!string.IsNullOrEmpty(def.PropertyDef.Description)) { list.Add(new DescriptionAttribute(def.PropertyDef.Description)); } if (!string.IsNullOrEmpty(def.PropertyDef.DisplayName)) { list.Add(new DisplayNameAttribute(def.PropertyDef.DisplayName)); } if (def.PropertyDef.Attributes != null) { foreach (var item in def.PropertyDef.Attributes) { list.Add(item.Attribute); } } return(list.ToArray()); }
public void ReadRightMouseClick(XmlNode objectNode, ref ObjectDef def, MainWindow win) { if (def.button != null) { switch (objectNode.SelectSingleNode(".//rightclick").InnerText) { case "toggle": def.button.PreviewMouseRightButtonDown += new MouseButtonEventHandler(win.ClickToggle); break; case "on": def.button.PreviewMouseRightButtonDown += new MouseButtonEventHandler(win.ClickOn); break; case "cycle": def.button.PreviewMouseRightButtonDown += new MouseButtonEventHandler(win.ClickCycle); break; case "cycle_off": def.button.PreviewMouseRightButtonDown += new MouseButtonEventHandler(win.ClickCycleOff); break; case "cycle_invert": def.button.PreviewMouseRightButtonDown += new MouseButtonEventHandler(win.ClickCycleInvert); break; case "off": default: def.button.PreviewMouseRightButtonDown += new MouseButtonEventHandler(win.ClickOff); break; } } }
Task ISubSystem.Start() { return(Task.Factory.StartNew(() => { var settings = StoryTellerEnvironment.Get <SerenityEnvironment>(); WebDriverSettings.Import(settings); FubuMvcPackageFacility.PhysicalRootPath = _settings.PhysicalPath; _runtime = _runtimeSource(); var browserLifecycle = WebDriverSettings.GetBrowserLifecyle(ChooseBrowserType()); _hosting = _settings.RootUrl.IsEmpty() ? (ISerenityHosting) new KatanaHosting() : new ExternalHosting(); _application = _hosting.Start(_settings, _runtime, browserLifecycle); _applicationAlterations.Each(x => x(_application)); _binding = _application.Services.GetInstance <BindingRegistry>(); _bindingRegistrations.Each(x => x(_binding)); configureApplication(_application, _binding); _contextualProviders = _runtime.Factory.GetAll <IContextualInfoProvider>(); _runtime.Facility.Register(typeof(IApplicationUnderTest), ObjectDef.ForValue(_application)); _runtime.Facility.Register(typeof(IRemoteSubsystems), ObjectDef.ForValue(this)); })); }
protected override void configureObject(ObjectDef def) { def.Child(new ViewPath { ViewName = _viewName }); }
/// <summary> /// Adds the specified <see cref="IAuthorizationRule{T}"/> /// </summary> /// <param name="ruleType">Closed generic rule type</param> /// <returns></returns> public ObjectDef AddRule(Type ruleType) { var openRuleType = ruleType .FindInterfaceThatCloses(typeof(IAuthorizationRule <>)); if (openRuleType == null) { throw new ArgumentOutOfRangeException("ruleType", "ruleType must close IAuthorizationRule<T>"); } var modelType = openRuleType .GetGenericArguments() .First(); var topDef = new ObjectDef(typeof(AuthorizationPolicy <>).MakeGenericType(modelType)); _policies.Add(topDef); var ruleObjectDef = new ObjectDef(ruleType); topDef.Dependency(typeof(IAuthorizationRule <>).MakeGenericType(modelType), ruleObjectDef); return(ruleObjectDef); }
protected override void configureObject(ObjectDef def) { def.DependencyByValue(new ViewPath { ViewName = _viewName }); }
protected override void Read(ClientProcessor psr, NReader rdr) { Tiles = new TileData[rdr.ReadInt16()]; for (var i = 0; i < Tiles.Length; i++) { Tiles[i] = new TileData { X = rdr.ReadInt16(), Y = rdr.ReadInt16(), Tile = (Tile)rdr.ReadByte() }; } NewObjects = new ObjectDef[rdr.ReadInt16()]; for (var i = 0; i < NewObjects.Length; i++) { NewObjects[i] = ObjectDef.Read(rdr); } RemovedObjectIds = new int[rdr.ReadInt16()]; for (var i = 0; i < RemovedObjectIds.Length; i++) { RemovedObjectIds[i] = rdr.ReadInt32(); } }
protected override ObjectDef buildObjectDef() { return(ObjectDef.ForType <AuthorizationBehavior>(x => { x.EnumerableDependenciesOf <IAuthorizationPolicy>().AddRange(_policies); })); }
private ObjectDef buildObjectDef(DiagnosticLevel diagnosticLevel) { var topDef = Top.As <IContainerModel>().ToObjectDef(diagnosticLevel); if (diagnosticLevel == DiagnosticLevel.FullRequestTracing && !IsPartialOnly) { var objectDef = new ObjectDef(typeof(DiagnosticBehavior)) { Name = UniqueId.ToString() }; objectDef.DependencyByType <IActionBehavior>(topDef); topDef.Name = Guid.NewGuid().ToString(); var list = new List <ObjectDef>(); var def = topDef; while (def != null) { list.Add(def); def = def.FindDependencyDefinitionFor <IActionBehavior>(); } return(objectDef); } return(topDef); }
public void ReadObjectNodes(XmlDocument doc, MainWindow win) { XmlNodeList objectNodeList = doc.SelectNodes("//object"); foreach (XmlNode objectNode in objectNodeList) { ObjectDef def = new ObjectDef(); def.Setup(); ReadObjectCoreData(objectNode, ref def, win); ReadObjectNames(objectNode, ref def); if (def.useRandomTextSelection == true) { ReadObjectRandomTextData(objectNode, ref def); } else { ReadObjectTextData(objectNode, ref def); } if (def.useRandomImageSelection == true) { ReadObjectRandomImageData(objectNode, ref def); } else { ReadObjectOnImages(objectNode, ref def); ReadObjectOffImages(objectNode, ref def); } def.PostLoad(); objectList.Add(def); } }
protected override ObjectDef buildObjectDef() { var objectDef = new ObjectDef(typeof(AuthorizationBehavior)); objectDef.Dependencies.Add(_policies); return objectDef; }
private void addStringConversions(DisplayConversionRegistry conversions) { var registry = new ServiceRegistry(); registry.AddService(typeof(DisplayConversionRegistry), ObjectDef.ForValue(conversions)); _configuration.Add(registry); }
public static void ConfigureCreateCommand(ObjectDef m, string schemaName, SqlCommand cmd, IEnumerable <object> values = null) { cmd.CommandType = CommandType.Text; string entityName = m.EntityName; StringBuilder sb = new StringBuilder(); StringBuilder sbParams = new StringBuilder(); sb.AppendLine(string.Format("INSERT INTO [{0}].[{1}](", schemaName, entityName)); var q = m.Properties.Where(p => !p.HasIgnoreColumn(DataOperation.Create)).OrderBy(p => p.PropertyOrder); //.Where(p => p.AllowCreate && !p.AutoGenerated).OrderBy(p => p.PropertyOrder); for (int i = 0; i < q.Count(); i++) { ObjectDefProperty mp = q.ElementAt(i); var entityPropName = mp.ColumnName; // (from mep in m.ModelEntityMappings where mep.ModelPropertyName.Equals(mp.Name) select mep.EntityPropertyName).SingleOrDefault(); if (i == 0) { sb.AppendLine(string.Format("\t[{0}]", entityPropName)); sbParams.AppendLine(string.Format("\t@{0}", entityPropName)); } else { sb.AppendLine(string.Format("\t, [{0}]", entityPropName)); sbParams.AppendLine(string.Format("\t, @{0}", entityPropName)); } if (values != null) { cmd.Parameters.AddWithValue("@" + entityPropName, values.ElementAt(i) != null ? values.ElementAt(i) : DBNull.Value); } } sb.AppendLine(")"); sb.AppendLine("VALUES("); sb.AppendLine(sbParams.ToString()); sb.AppendLine(")"); cmd.CommandText = sb.ToString(); }
protected override void configureObject(ObjectDef def) { def.Child(new ViewPath { ViewName = _viewName }); }
public void name_of_the_instance_comes_from_the_name_of_the_inner_object_def() { var def = new ObjectDef(typeof(FakeJsonBehavior)); var instance = new ObjectDefInstance(def); instance.Name.ShouldEqual(def.Name); }
public void ReadLeftMouseCLick(XmlNode objectNode, ref ObjectDef def, MainWindow win) { if (def.button != null) { switch (objectNode.SelectSingleNode(".//leftclick").InnerText) { case "toggle": def.button.Click += new RoutedEventHandler(win.ClickToggle); break; case "on": def.button.Click += new RoutedEventHandler(win.ClickOn); break; case "cycle": def.button.Click += new RoutedEventHandler(win.ClickCycle); break; case "cycle_off": def.button.Click += new RoutedEventHandler(win.ClickCycleOff); break; case "cycle_invert": def.button.Click += new RoutedEventHandler(win.ClickCycleInvert); break; case "off": default: def.button.Click += new RoutedEventHandler(win.ClickOff); break; } } }
public void ReadObjectCoreData(XmlNode objectNode, ref ObjectDef def, MainWindow win) { if (objectNode.SelectSingleNode(".//name") != null) { def.name = objectNode.SelectSingleNode(".//name").InnerText; def.nameList.Add(new string[] { def.name, "0", "0" }); } if (objectNode.SelectSingleNode(".//button") != null) { def.button = ResolveButtonName(win, objectNode.SelectSingleNode(".//button").InnerText); def.textBlock = ResolveTextBlockName(win, objectNode.SelectSingleNode(".//button").InnerText); } if (objectNode.SelectSingleNode(".//leftclick") != null) { ReadLeftMouseCLick(objectNode, ref def, win); } if (objectNode.SelectSingleNode(".//rightclick") != null) { ReadRightMouseClick(objectNode, ref def, win); } if (objectNode.SelectSingleNode(".//use_random_text_selection") != null) { def.useRandomTextSelection = bool.Parse(objectNode.SelectSingleNode(".//use_random_text_selection").InnerText); } if (objectNode.SelectSingleNode(".//use_random_image_selection") != null) { def.useRandomImageSelection = bool.Parse(objectNode.SelectSingleNode(".//use_random_image_selection").InnerText); } }
public ObjectDefRegistration(ContainerBuilder builder, ObjectDef definition, bool isSingleton, bool isDependency) { _builder = builder; _definition = definition; _isSingleton = isSingleton; _isDependency = isDependency; }
public void build_an_object_with_dependencies() { var request = new InMemoryFubuRequest(); var def = new ObjectDef(typeof(FakeJsonBehavior)); def.DependencyByValue(typeof(IFubuRequest), request); var jsonWriter = def.DependencyByType(typeof(IJsonWriter), typeof(AjaxAwareJsonWriter)); jsonWriter.DependencyByType(typeof(IOutputWriter), typeof(OutputWriter)); jsonWriter.DependencyByType(typeof(IRequestData), typeof(InMemoryRequestData)); def.DependencyByType(typeof(IRequestData), typeof(InMemoryRequestData)); var container = new Container(x => { x.For <IFileSystem>().Use <FileSystem>(); x.For <IHttpWriter>().Use <NulloHttpWriter>(); x.For <IActionBehavior>().Use(new ObjectDefInstance(def)); x.For <ILogger>().Use <Logger>(); x.For <ISystemTime>().Use(SystemTime.Default); }); var jsonBehavior = container.GetInstance <IActionBehavior>().ShouldBeOfType <FakeJsonBehavior>(); jsonBehavior.Writer.ShouldBeOfType <AjaxAwareJsonWriter>(); jsonBehavior.Request.ShouldBeTheSameAs(request); }
public void uses_explicit_output_cache_if_one_is_specified() { theNode.OutputCache = ObjectDef.ForType <FakeOutputCache>(); toObjectDef().FindDependencyDefinitionFor <IOutputCache>() .ShouldEqual(theNode.OutputCache); }
private IConditional build(ObjectDef def) { theFacility.Register(typeof(IConditional), def); theFacility.BuildFactory(); return(theContainer.GetInstance <IConditional>(def.Name)); }
protected override ObjectDef toWriterDef() { var def = new ObjectDef(typeof(ViewWriter<>), ResourceType); def.DependencyByType<IViewFactory>(_token.ToViewFactoryObjectDef()); return def; }
public void AddRegistration(Type abstraction, ObjectDef definition, bool isSingleton) { _registrations.Add( builder => { var registration = new ObjectDefRegistration(builder, definition, isSingleton, false); registration.Register(abstraction); }); }
protected override ObjectDef buildObjectDef() { var tracerDef = new ObjectDef(typeof (BehaviorTracer)); var chain = ParentChain(); tracerDef.DependencyByValue(new BehaviorCorrelation(Next)); return tracerDef; }
protected override ObjectDef toWriterDef() { var objectDef = new ObjectDef(typeof (MediaWriter<>).MakeGenericType(_resourceType)); if (Links.Dependency != null) objectDef.Dependency(Links.Dependency); if (Projection.Dependency != null) objectDef.Dependency(Projection.Dependency); if (Document.Dependency != null) objectDef.Dependency(Document.Dependency); return objectDef; }
private ObjectDef buildConditionalInvokerDef(ObjectDef objectDef) { var invokerDef = ObjectDef.ForType<ConditionalBehaviorInvoker>(); var conditionalBehaviorDef = invokerDef .DependencyByType<IConditionalBehavior, ConditionalBehavior>(); conditionalBehaviorDef.DependencyByType<IActionBehavior>(objectDef); conditionalBehaviorDef.DependencyByType<IConditional>(_conditionalDef); return invokerDef; }
/// <summary> /// Adds a concrete type to the list or enumeration /// </summary> /// <param name="type"></param> /// <returns></returns> public ObjectDef AddType(Type type) { var objectDef = new ObjectDef(type); objectDef.ValidatePluggabilityTo(ElementType); _items.Add(objectDef); return objectDef; }
private void addHarnessToServices(BehaviorGraph graph, Type type) { var key = type.NameForGrid(); var harnessType = typeof (SmartGridHarness<>).MakeGenericType(type); var objectDef = new ObjectDef(harnessType); objectDef.Name = key; graph.Services.AddService(typeof(ISmartGridHarness), objectDef); }
public ObjectDef ToObjectDef(DiagnosticLevel level) { var objectDef = new ObjectDef(typeof (MediaWriter<>).MakeGenericType(_inputType)); if (Links.Dependency != null) objectDef.Dependency(Links.Dependency); if (Projection.Dependency != null) objectDef.Dependency(Projection.Dependency); if (Document.Dependency != null) objectDef.Dependency(Document.Dependency); return objectDef; }
public FubuTransportServiceRegistry() { var eventAggregatorDef = FubuTransport.UseSynchronousLogging ? ObjectDef.ForType<SynchronousEventAggregator>() : ObjectDef.ForType<EventAggregator>(); eventAggregatorDef.IsSingleton = true; SetServiceIfNone(typeof(IEventAggregator), eventAggregatorDef); var stateCacheDef = new ObjectDef(typeof(SagaStateCacheFactory)); stateCacheDef.IsSingleton = true; SetServiceIfNone(typeof(ISagaStateCacheFactory), stateCacheDef); SetServiceIfNone<IChainInvoker, ChainInvoker>(); SetServiceIfNone<IEnvelopeSender, EnvelopeSender>(); AddService<IMessageSerializer, XmlMessageSerializer>(); AddService<IActivator, FubuTransportationActivator>(); SetServiceIfNone<IServiceBus, ServiceBus>(); SetServiceIfNone<IEnvelopeSerializer, EnvelopeSerializer>(); SetServiceIfNone<IHandlerPipeline, HandlerPipeline>(); AddService<ILogListener, EventAggregationListener>(); if (FubuTransport.ApplyMessageHistoryWatching || FubuMode.InTestingMode()) { AddService<IListener, MessageWatcher>(); var def = ObjectDef.ForType<MessagingSession>(); def.IsSingleton = true; SetServiceIfNone(typeof(IMessagingSession), def); AddService<ILogListener, MessageRecordListener>(); } if (FubuMode.InTestingMode()) { AddService<IActivator, TransportCleanupActivator>(); } AddService<IEnvelopeHandler, DelayedEnvelopeHandler>(); AddService<IEnvelopeHandler, ResponseEnvelopeHandler>(); AddService<IEnvelopeHandler, ChainExecutionEnvelopeHandler>(); AddService<IEnvelopeHandler, NoSubscriberHandler>(); SetServiceIfNone<IMessageExecutor, MessageExecutor>(); SetServiceIfNone<IOutgoingSender, OutgoingSender>(); SetServiceIfNone<IAsyncHandling, AsyncHandling>(); subscriptions(); }
public void build_an_object_with_no_children() { Type type = typeof (TestBehavior); var def = new ObjectDef { Type = type }; var container = new Container(x => { x.For<IActionBehavior>().UseInstance(new ObjectDefInstance(def)); }); container.GetInstance<IActionBehavior>().ShouldBeOfType<TestBehavior>(); }
protected override ObjectDef BuildObjectDef() { var messageType = Chain.MessageType; var handlerDef = new ObjectDef(typeof (ConditionalHandler<>), messageType); var dependencyType = typeof (ICondition<>).MakeGenericType(messageType); var conditionType = ConditionType; if(conditionType.IsOpenGeneric()) { conditionType = ConditionType.MakeGenericType(messageType); } handlerDef.DependencyByType(dependencyType, conditionType); return handlerDef; }
protected override ObjectDef toWriterDef() { var def = new ObjectDef(typeof(ViewWriter<>), ResourceType); def.DependencyByType<IViewFactory>(_token.ToViewFactoryObjectDef()); var activator = new ObjectDef(typeof (FubuPageActivator<>), _token.ViewModel); activator.DependencyByValue(typeof (IViewToken), _token); def.Dependency(typeof (IFubuPageActivator), activator); return def; }
public void Should_satisfy_dependency() { var def = new ObjectDef(typeof(NeedListOfDoers)); var doer1 = new ASomethingDoer(); var doers = new ListDependency(typeof (IEnumerable<ISomethingDoer>)); doers.AddValue(doer1); doers.AddType(typeof (BSomethingDoer)); def.Dependency(doers); def.Dependencies.ShouldHaveCount(1); }
private ObjectDef createTracerDef(ObjectDef objectDef) { var tracerDef = new ObjectDef(typeof(BehaviorTracer)); tracerDef.DependencyByType<IActionBehavior>(objectDef); var chain = ParentChain(); tracerDef.DependencyByValue(new BehaviorCorrelation { ChainId = chain == null ? Guid.Empty : chain.UniqueId, BehaviorId = UniqueId }); return tracerDef; }
public ObjectDef RepositoryFor(SagaTypes sagaTypes) { if (sagaTypes.StateType.GetProperty(SagaTypes.Id) == null) { return null; } var objectDef = new ObjectDef(typeof (InMemorySagaRepository<,>), sagaTypes.StateType, sagaTypes.MessageType); objectDef.DependencyByValue(typeof(Func<,>).MakeGenericType(sagaTypes.StateType, typeof(Guid)), sagaTypes.ToSagaIdFunc()); objectDef.DependencyByValue(typeof(Func<,>).MakeGenericType(sagaTypes.MessageType, typeof(Guid)), sagaTypes.ToCorrelationIdFunc()); return objectDef; }
protected override ObjectDef buildObjectDef() { if (Repository == null) { throw new InvalidOperationException( "something descriptive here saying you don't know how to do the repo for the saga"); } var def = new ObjectDef(typeof (SagaBehavior<,,>), _types.StateType, _types.MessageType, _types.HandlerType); var repositoryType = typeof (ISagaRepository<,>).MakeGenericType(_types.StateType, _types.MessageType); def.Dependency(repositoryType, Repository); return def; }
public WindsorDependencyVisitor(Type serviceType, ObjectDef objectDef, bool isDependency) { _objectDef = objectDef; _registration = map(serviceType, objectDef, false); // NOTE[MT]: if class is registered as dependency // it should be registered as default service to pass // auto_wiring_applies_even_when_another_dependency_is_set_explicitly test if (isDependency && serviceType.IsClass) _components.Add(map(serviceType, objectDef, true)); _registration = map(serviceType, objectDef, false); _components.Add(_registration); }
public void Init(int w, int h) { Width = w; Height = h; Tiles = new Tile[w][]; for (int i = 0; i < w; i++) Tiles[i] = new Tile[h]; Entities = new ObjectDef[w][][]; for (int i = 0; i < w; i++) { Entities[i] = new ObjectDef[h][]; for (int j = 0; j < h; j++) { Entities[i][j] = new ObjectDef[0]; } } }
protected override void configureObject(ObjectDef def) { ObjectDef currentCandidate = null; foreach (var pair in _outputs.Reverse()) { var candidate = new ObjectDef(typeof(ConditionalOutput)); candidate.Child(typeof(Func<OutputFormatDetector, bool>), pair.Predicate); candidate.Dependencies.Add(new ConfiguredDependency { Definition = pair.OutputNode.ToObjectDef(), DependencyType = typeof(IActionBehavior) }); if (currentCandidate != null) { candidate.Dependencies.Add(new ConfiguredDependency { Definition = currentCandidate, DependencyType = typeof(ConditionalOutput) }); } currentCandidate = candidate; } def.Dependencies.Add(new ConfiguredDependency { Definition = currentCandidate, DependencyType = typeof(ConditionalOutput) }); }
private static ComponentRegistration map(Type serviceType, ObjectDef def, bool isDefault) { var c = Component.For(serviceType); if (def.Value != null) c.Instance(def.Value); else c.ImplementedBy(def.Type); if (isDefault) { c.IsDefault().LifestyleScoped(); } else { c.Named(def.Name).IsFallback(); if (def.IsSingleton) c.LifestyleSingleton(); else c.LifestyleScoped(); } return c; }
public static IActionBehavior BuildBehavior(ServiceArguments arguments, ObjectDef behaviorDef, Action<IContainerFacility> configuration) { var id = Guid.NewGuid(); behaviorDef.Name = id.ToString(); var facility = New( x => { configuration(x); x.Register(typeof(IActionBehavior), behaviorDef); }); var behavior = facility.BuildBehavior(arguments, id); // StartInnerBehavior() is not part of the core interface, but I had to have something to get at the real top level // behavior within the context of an Autofac nested container. return behavior.As<NestedAutofacContainerBehavior>().StartInnerBehavior(); }
public void build_an_object_with_a_list_dependency() { var def = new ObjectDef(typeof (ClassWithSomethings)); var listDependency = def.ListDependenciesOf<ISomething>(); listDependency.AddType(typeof (SomethingA)); listDependency.AddType(typeof (SomethingB)); listDependency.AddValue(new SomethingC()); var instance = new ObjectDefInstance(def); var container = new Container(); var @object = container.GetInstance<ClassWithSomethings>(instance); @object.Somethings[0].ShouldBeOfType<SomethingA>(); @object.Somethings[1].ShouldBeOfType<SomethingB>(); @object.Somethings[2].ShouldBeOfType<SomethingC>(); }
protected override void Read(NReader rdr) { Tiles = new TileData[rdr.ReadInt16()]; for (var i = 0; i < Tiles.Length; i++) { Tiles[i] = new TileData() { X = rdr.ReadInt16(), Y = rdr.ReadInt16(), Tile = (Tile)rdr.ReadByte() }; } NewObjects = new ObjectDef[rdr.ReadInt16()]; for (var i = 0; i < NewObjects.Length; i++) NewObjects[i] = ObjectDef.Read(rdr); RemovedObjectIds = new int[rdr.ReadInt16()]; for (var i = 0; i < RemovedObjectIds.Length; i++) RemovedObjectIds[i] = rdr.ReadInt32(); }