public void AddService(Type t, object owner, object instance) { Guard.ArgumentNotNull(t, nameof(t)); Guard.ArgumentNotNull(owner, nameof(owner)); Guard.ArgumentNotNull(instance, nameof(instance)); string contract = AttributedModelServices.GetContractName(t); if (string.IsNullOrEmpty(contract)) { throw new GitHubLogicException("Every type must have a contract name"); } // we want to remove stale instances of a service, if they exist, regardless of who put them there RemoveService(t, null); var batch = new CompositionBatch(); var part = batch.AddExportedValue(contract, instance); if (part == null) { throw new GitHubLogicException("Adding an exported value must return a non-null part"); } tempParts.Add(contract, new OwnedComposablePart { Owner = owner, Part = part }); TempContainer.Compose(batch); }
public object TryGetService(Type serviceType) { string contract = AttributedModelServices.GetContractName(serviceType); var instance = AddToDisposables(TempContainer.GetExportedValueOrDefault <object>(contract)); if (instance != null) { return(instance); } var sp = initialized ? syncServiceProvider : asyncServiceProvider; instance = sp.GetService(serviceType); if (instance != null) { return(instance); } instance = AddToDisposables(ExportProvider.GetExportedValues <object>(contract).FirstOrDefault(x => contract.StartsWith("github.", StringComparison.OrdinalIgnoreCase) ? x.GetType().Assembly.GetName().Version == currentVersion : true)); if (instance != null) { return(instance); } instance = GitServiceProvider?.GetService(serviceType); if (instance != null) { return(instance); } return(null); }
public ActorRef ResolveActorRef(ActorPath actorPath) { if (HasAddress(actorPath.Address)) { if (actorPath.Elements.Head() == "remote") { if (actorPath.ToStringWithoutAddress() == "/remote") { return(RemoteDaemon); } //skip ""/"remote", string[] parts = actorPath.Elements.Drop(1).ToArray(); return(RemoteDaemon.GetChild(parts)); } if (actorPath.Elements.Head() == "temp") { //skip ""/"temp", string[] parts = actorPath.Elements.Drop(1).ToArray(); return(TempContainer.GetChild(parts)); } //standard var rootGuardian = RootGuardian; if (actorPath.ToStringWithoutAddress() == "/") { return(rootGuardian); } return(rootGuardian.GetChild(actorPath.Elements)); } return(new RemoteActorRef(Transport, Transport.LocalAddressForRemote(actorPath.Address), actorPath, ActorRef.Nobody, Props.None, Deploy.None)); }
public object TryGetService(Type serviceType) { Guard.ArgumentNotNull(serviceType, nameof(serviceType)); if (!initializingLogging && log.Factory.Configuration == null) { initializingLogging = true; try { var logging = TryGetService(typeof(ILoggingConfiguration)) as ILoggingConfiguration; logging.Configure(); } catch { #if DEBUG throw; #endif } } string contract = AttributedModelServices.GetContractName(serviceType); var instance = AddToDisposables(TempContainer.GetExportedValueOrDefault <object>(contract)); if (instance != null) { return(instance); } var sp = initialized ? syncServiceProvider : asyncServiceProvider; instance = sp.GetService(serviceType); if (instance != null) { return(instance); } instance = AddToDisposables(ExportProvider.GetExportedValues <object>(contract).FirstOrDefault(x => contract.StartsWith("github.", StringComparison.OrdinalIgnoreCase) ? x.GetType().Assembly.GetName().Version == currentVersion : true)); if (instance != null) { return(instance); } instance = GitServiceProvider?.GetService(serviceType); if (instance != null) { return(instance); } return(null); }
public void AddService(Type t, object owner, object instance) { string contract = AttributedModelServices.GetContractName(t); Debug.Assert(!string.IsNullOrEmpty(contract), "Every type must have a contract name"); // we want to remove stale instances of a service, if they exist, regardless of who put them there RemoveService(t, null); var batch = new CompositionBatch(); var part = batch.AddExportedValue(contract, instance); Debug.Assert(part != null, "Adding an exported value must return a non-null part"); tempParts.Add(contract, new OwnedComposablePart { Owner = owner, Part = part }); TempContainer.Compose(batch); }
/// <summary> /// Removes a service from the catalog /// </summary> /// <param name="t">The type we want to remove</param> /// <param name="owner">The owner, which either has to match what was passed to AddService, /// or if it's null, the service will be removed without checking for ownership</param> public void RemoveService(Type t, [AllowNull] object owner) { string contract = AttributedModelServices.GetContractName(t); Debug.Assert(!string.IsNullOrEmpty(contract), "Every type must have a contract name"); OwnedComposablePart part; if (tempParts.TryGetValue(contract, out part)) { if (owner != null && part.Owner != owner) { return; } tempParts.Remove(contract); var batch = new CompositionBatch(); batch.RemovePart(part.Part); TempContainer.Compose(batch); } }
/// <summary> /// Resolves the actor reference. /// </summary> /// <param name="actorPath">The actor path.</param> /// <returns>ActorRef.</returns> /// <exception cref="System.NotSupportedException">The provided actor path is not valid in the LocalActorRefProvider</exception> public override ActorRef ResolveActorRef(ActorPath actorPath) { if (Address.Equals(actorPath.Address)) { if (actorPath.Elements.Head() == "temp") { //skip ""/"temp", string[] parts = actorPath.Elements.Drop(1).ToArray(); return(TempContainer.GetChild(parts)); } //standard ActorCell currentContext = RootCell; foreach (string part in actorPath.Elements) { currentContext = ((LocalActorRef)currentContext.Child(part)).Cell; } return(currentContext.Self); } throw new NotSupportedException("The provided actor path is not valid in the LocalActorRefProvider"); }
public override ActorRef ResolveActorRef(ActorPath actorPath) { if (HasAddress(actorPath.Address)) { if (actorPath.Elements.Head() == "remote") { if (actorPath.ToStringWithoutAddress() == "/remote") { return(RemoteDaemon); } //skip ""/"remote", string[] parts = actorPath.Elements.Drop(1).ToArray(); return(RemoteDaemon.GetChild(parts)); } if (actorPath.Elements.Head() == "temp") { //skip ""/"temp", string[] parts = actorPath.Elements.Drop(1).ToArray(); return(TempContainer.GetChild(parts)); } //standard ActorCell currentContext = RootCell; if (actorPath.ToStringWithoutAddress() == "/") { return(currentContext.Self); } foreach (string part in actorPath.Elements) { currentContext = ((LocalActorRef)currentContext.Child(part)).Cell; } return(currentContext.Self); } return(new RemoteActorRef(Transport, Transport.LocalAddressForRemote(actorPath.Address), actorPath, ActorRef.Nobody, Props.None, Deploy.None)); }
/// <summary> /// Unregisters the temporary actor. /// </summary> /// <param name="path">The path.</param> public void UnregisterTempActor(ActorPath path) { TempContainer.RemoveChild(path.Name); }
/// <summary> /// Registers the temporary actor. /// </summary> /// <param name="actorRef">The actor reference.</param> /// <param name="path">The path.</param> public void RegisterTempActor(InternalActorRef actorRef, ActorPath path) { TempContainer.AddChild(path.Name, actorRef); }