public static IDisposable Publish <T>( [NotNull] this IServicePublisher publisher, [NotNull] Func <IServicePublisher, T> instanceFactory) where T : class { Code.NotNull(publisher, nameof(publisher)); Code.NotNull(instanceFactory, nameof(instanceFactory)); // DONTTOUCH: for valid overload resolution (fails on net35). #if LESSTHAN_NET40 // Hack for CS0030 Cannot convert type 'System.Func<CodeJam.Services.IServicePublisher, T>' to 'System.Func<CodeJam.Services.IServicePublisher, object>' return(publisher.Publish(typeof(T), new Func <IServicePublisher, object>(sp => instanceFactory(sp)))); #else // ReSharper disable once RedundantCast return(publisher.Publish(typeof(T), (Func <IServicePublisher, object>)instanceFactory)); #endif }
/// <summary> /// Creates and publish app resource server implementation. /// </summary> public static IAppResourceServer CreateAndPublishResourceServer(IServicePublisher publisher, string schemeName) { var srv = CreateResourceServer(publisher, schemeName); publisher.Publish(srv); return(srv); }
public static IDisposable Publish <T>( [NotNull] this IServicePublisher publisher, [NotNull] T serviceInstance) where T : class { Code.NotNull(publisher, nameof(publisher)); Code.NotNull(serviceInstance, nameof(serviceInstance)); return(publisher.Publish(typeof(T), serviceInstance)); }
public static IDisposable Publish <T>( [NotNull] this IServicePublisher publisher, [NotNull] Func <IServicePublisher, T> instanceFactory) where T : class { Code.NotNull(publisher, nameof(publisher)); Code.NotNull(instanceFactory, nameof(instanceFactory)); return(publisher.Publish(typeof(T), instanceFactory)); }
/// <summary> /// 服务订阅 /// </summary> /// <param name="servicePublisher"></param> /// <param name="serviceTypes">服务类型</param> /// <param name="host">服务Host</param> /// <param name="port">服务端口</param> /// <param name="serializerName">序列化器名称</param> /// <returns></returns> public static IServicePublisher Publish(this IServicePublisher servicePublisher, IEnumerable <Type> serviceTypes, string host, int port, string serializerName) { foreach (var serviceType in serviceTypes) { servicePublisher.Publish(serviceType, host, port, serializerName); } return(servicePublisher); }
public static IDisposable Publish <T>( [NotNull] this IServicePublisher publisher, [NotNull] Func <IServicePublisher, T> instanceFactory) where T : class { Code.NotNull(publisher, nameof(publisher)); Code.NotNull(instanceFactory, nameof(instanceFactory)); // DONTTOUCH: for valid overload resolution (fails on net35). // ReSharper disable once RedundantCast return(publisher.Publish(typeof(T), instanceFactory)); }
/// <summary> /// Create and publish active parts manager. /// </summary> public static ActivePartManager CreateAndPublishManager([NotNull] IServicePublisher servicePublisher) { if (servicePublisher == null) { throw new ArgumentNullException(nameof(servicePublisher)); } var mgr = new ActivePartManager(servicePublisher); servicePublisher.Publish <IActivePartManager>(mgr); return(mgr); }
/// <summary> /// 使用服务发布 /// </summary> /// <param name="nodeServer"></param> /// <param name="servicePublisher">服务发布器</param> /// <param name="serializerName">序列化器名称</param> /// <returns></returns> public static INodeServer UseServicePublish(this INodeServer nodeServer, IServicePublisher servicePublisher, string serializerName) { nodeServer.OnStarted += arg => { var serviceTypes = arg.Routes.Where(r => r.Enabled).Select(r => r.ServiceType).Distinct(); servicePublisher.Publish(serviceTypes, arg.Host, arg.Port, serializerName); }; nodeServer.OnStopped += arg => { servicePublisher.Dispose(); }; return(nodeServer); }