public override void Initialize(IServiceRegister register) { base.Initialize(register); register.ScanWithDefaultConventions(this); register.RegisterJobs(this); register.RegisterEventSubscribers(this); }
/// <summary> /// /// </summary> /// <param name="action"></param> /// <param name="originalType"></param> /// <param name="operationType"></param> /// <param name="serviceRegister"></param> protected OperationInfo(string action, Type originalType, OperationInfoType operationType, IServiceRegister serviceRegister) { this.action = action; this.originalType = originalType; this.serviceRegister = serviceRegister; this.operationType = operationType; this.normalizedType = this.serviceRegister.TryToNormalize(originalType); string messageError; switch (operationType) { case OperationInfoType.Parameter: messageError = "The service is not able to use the given object parameter type for serializing / deserializing objects, in order to resolve this kind of problem, you must to use a serviceTypeRegister on *.config file"; break; case OperationInfoType.Result: messageError = "The service is not able to use the given object return type for serializing / deserializing objects, in order to resolve this kind of problem, you must to use a serviceTypeRegister on *.config file"; break; default: messageError = "Operation Type unknown."; break; } if (normalizedType == null && serviceRegister.CheckOperationTypes) throw new TypeUnresolvedException(messageError, originalType); // }
public void RegisterDependencies(IServiceRegister serviceRegister) { if (serviceRegister is null) { throw new ArgumentNullException(nameof(serviceRegister)); } serviceRegister.Register((IServiceProvider ServiceProvider) => { CookieOptions option = new CookieOptions { Expires = DateTime.Now.AddDays(-10) }; HttpContext context = ServiceProvider.GetService <HttpContext>(); ISession session = context.Session; TeaEncryptor tea = new TeaEncryptor(session.Get(SecurityService.SECURITY_TOKEN_PASSWORD_NAME)); string fingerPrintJson = tea.Decrypt(context.Request.Cookies["X-Session"]); SecurityToken securityToken = JsonConvert.DeserializeObject <SecurityToken>(fingerPrintJson); context.Response.Cookies.Append("X-Session", "", option); return(securityToken); }, ServiceLifetime.Singleton); }
public static IServiceRegister EnableInterception(this IServiceRegister serviceRegister, Action <IInterceptorRegistrator> configure) { var registrator = new InterceptorRegistrator(serviceRegister); configure(registrator); return(registrator.Register()); }
/// <summary> /// /// </summary> /// <param name="action"></param> /// <param name="originalType"></param> /// <param name="operationType"></param> /// <param name="serviceRegister"></param> protected OperationInfo(string action, Type originalType, OperationInfoType operationType, IServiceRegister serviceRegister) { this.action = action; this.originalType = originalType; this.serviceRegister = serviceRegister; this.operationType = operationType; this.normalizedType = this.serviceRegister.TryToNormalize(originalType); string messageError; switch (operationType) { case OperationInfoType.Parameter: messageError = "The service is not able to use the given object parameter type for serializing / deserializing objects, in order to resolve this kind of problem, you must to use a serviceTypeRegister on *.config file"; break; case OperationInfoType.Result: messageError = "The service is not able to use the given object return type for serializing / deserializing objects, in order to resolve this kind of problem, you must to use a serviceTypeRegister on *.config file"; break; default: messageError = "Operation Type unknown."; break; } if (normalizedType == null && serviceRegister.CheckOperationTypes) { throw new TypeUnresolvedException(messageError, originalType); } // }
public MicroHost(IMicroExecutor serviceExecutor, IMicroListener microListener, IServiceRegister serviceRegister, IMicroEntryFactory entryFactory) : base(serviceExecutor, microListener) { _serviceRegister = serviceRegister; _entryFactory = entryFactory; _logger = LogManager.Logger <MicroHost>(); }
public override void Register(IServiceRegister register) { //Register the protobufnet serializers register.Register <ProtobufnetSerializerStrategy>(this.getFlags(), typeof(ISerializerStrategy)); register.Register <ProtobufnetDeserializerStrategy>(this.getFlags(), typeof(IDeserializerStrategy)); register.Register <ProtobufnetRegistry>(this.getFlags(), typeof(ISerializerRegistry)); }
public override void Register(IServiceRegister register) { //Just create a new collection and register it NetworkEntityCollection entityCollection = new NetworkEntityCollection(); register.Register(entityCollection, this.getFlags()); }
/// <summary> /// /// </summary> /// <param name="operation"></param> /// <param name="serviceRegister"></param> protected DispatchJsonMessageFormatter(OperationDescription operation, IServiceRegister serviceRegister) //: base (operation.Messages[1].Action, // operation.SyncMethod.GetParameters(), // operation.SyncMethod.ReturnType, // serviceRegister) : base(new ServiceOperation(operation, operation.Messages[1].Action), serviceRegister) { }
public MicroHost(ILogger <MicroHost> logger, IMicroExecutor serviceExecutor, IMicroListener microListener, IServiceRegister serviceRegister, IMicroEntryFactory entryFactory) : base(logger, serviceExecutor, microListener) { _serviceRegister = serviceRegister; _entryFactory = entryFactory; _logger = logger; }
/// <summary> /// Enables support of using multiple channels for clients operations /// </summary> /// <param name="serviceRegister">The register</param> /// <param name="channelsCount">Max count of channels</param> public static IServiceRegister EnableMultiChannelClientCommandDispatcher( this IServiceRegister serviceRegister, int channelsCount ) { return(serviceRegister.Register <IClientCommandDispatcher>( x => new MultiChannelClientCommandDispatcher(channelsCount, x.Resolve <IPersistentChannelFactory>()) )); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="action"></param> /// <param name="originalType"></param> /// <param name="serviceRegister"></param> public OperationParameter(string name, string action, Type originalType, IServiceRegister serviceRegister) : base(action, originalType, OperationInfoType.Parameter, serviceRegister) { //if (this.NormalizedType == null && serviceRegister.CheckOperationTypes) // throw new TypeUnresolvedException("The service is not able to use the given object parameter type for serializing / deserializing objects, in order to resolve this kind of problem, you must to use a serviceTypeRegister on *.config file", originalType); this.name = name; }
//TODO: Handle HTTPS cert issue public override void Register(IServiceRegister register) { register.RegisterAsImplementedInterfaces(TypeSafeHttpBuilder <IGameServerSessionService> .Create() .RegisterDefaultSerializers() .RegisterJsonNetSerializer() .RegisterDotNetHttpClient(@"http://localhost:5003") .Build()); //TODO: How should an instance server find its mediator? }
public static IServiceRegister UseMessageWaitAndRetryHandlerPolicy(this IServiceRegister registrar) { var policy = Policy .Handle <Exception>() .WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))); return(UseMessageHandlerPolicy(registrar, policy)); }
public override void RegisterServices(IServiceRegister register) { register.Singleton <TestSchema>(); register.Singleton <DIGraphType <SampleGraph, SampleSource> >(); register.Scoped <Service1>(); register.Scoped <Service2>(); // note: in this example, SampleGraph is not registered, but is created for every field resolver (except static methods) -- see DIGraphType.MemberInstanceFunc }
public RegisterService(IConfigAccessor configAccessor, IServiceRegister serviceRegister, IRuntimeEnvironment runtimeEnvironment, ILoggerFactory loggerFactory) : base(runtimeEnvironment, loggerFactory) { _serviceRegister = serviceRegister; _config = configAccessor.Get <InstrumentConfig>(); _transportConfig = configAccessor.Get <TransportConfig>(); }
/// <summary> /// Initializes a new instance of the <see cref="EasyContainer"/> class. /// </summary> /// <param name="filteringAssemblyProviderCallback">The filtering assembly provider callback.</param> /// <param name="containerActivator"></param> protected EasyContainer(Func <IFilteringAssemblyProvider> filteringAssemblyProviderCallback, Func <IValuableOption <UnableRegisterRule>, RegisterRuleContainer> containerActivator) { this.typeFinder = new DefaultTypeFinder(); this.ruleContainer = containerActivator == null ? new RegisterRuleContainer(this) : containerActivator(this); this.serviceRegister = new ServiceRegister(this.ruleContainer, this); this.scopeTracker = new DefaultLifetimeScopeTracker(); this.filteringAssemblyProviderCallback = filteringAssemblyProviderCallback; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); ////???需要注入的服务在 InjectionService.AdmServiceRegister.Register方法内注入即可 /// //services.AddScoped<IParaReferRepository(接口), ParaReferRepository(实现类)>(); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); //数据库连接 var conStr = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build()["ConnectionStrings:SqlServerConnectiion"]; services.AddDbContext <DccyDbContext>(options => options.UseSqlServer(conStr), ServiceLifetime.Scoped); //注入配置类 services.AddOptions(); services.Configure <AppSetting>(Configuration.GetSection("AppSetting")); #region 批量注入 //外部注入 string strValue = Configuration.GetSection("Appsetings").GetSection("key").Value; foreach (var item in GetClassName(strValue)) { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } //内部注入 IEnumerable <Type> serviceList = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(m => m.GetTypes()).Select(m => m.GetTypeInfo()) .Where(m => !m.IsAbstract && !m.IsInterface && typeof(IServiceRegister).GetTypeInfo().IsAssignableFrom(m)); foreach (Type type in serviceList) { IServiceRegister register = Activator.CreateInstance(type, true) as IServiceRegister; register.Register(services); } #endregion services.AddDistributedMemoryCache(); services.AddSession(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public override void RegisterServices(IServiceRegister register) { register.Transient <DogType>(); register.Transient <CatType>(); register.Transient <PetType>(); register.Transient <PersonType>(); register.Transient <NamedType>(); register.Singleton <UnionSchema>(); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceResolveContext"/> class. /// </summary> /// <param name="resolver">the service resolver using the context</param> /// <param name="register">the service register</param> /// <param name="constructionMode">the service construction mode for the resolve</param> /// <param name="serviceType">the type of the service being resolved</param> /// <param name="parentType">the type of the parent</param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="resolver"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="register"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="serviceType"/> is <see langword="null"/>. /// </exception> public ServiceResolveContext(IServiceResolver resolver, IServiceRegister register, ServiceConstructionMode constructionMode, Type serviceType, Type parentType = null) { ParentType = parentType; ConstructionMode = GetServiceConstructionMode(constructionMode, resolver); Resolver = resolver ?? throw new ArgumentNullException(nameof(resolver)); Register = register ?? throw new ArgumentNullException(nameof(register)); ServiceType = serviceType ?? throw new ArgumentNullException(nameof(serviceType)); }
//protected ClientJsonMessageFormatter(OperationDescription operation, ServiceEndpoint endpoint, IServiceRegister serviceRegister) // : base (operation.Messages[0].Action, // operation.SyncMethod.GetParameters(), // operation.SyncMethod.ReturnType, // serviceRegister) //{ // string endpointAddress = endpoint.Address.Uri.ToString(); // if (!endpointAddress.EndsWith("/")) // endpointAddress = endpointAddress + "/"; // this.operationUri = new Uri(endpointAddress + operation.Name); //} /// <summary> /// Initializes a new instance of the <see cref="ClientJsonMessageFormatter"/> class. /// </summary> /// <param name="operation">The operation.</param> /// <param name="endpoint">The endpoint.</param> /// <param name="serviceRegister">The service register.</param> protected ClientJsonMessageFormatter(OperationDescription operation, ServiceEndpoint endpoint, IServiceRegister serviceRegister) : base(new ServiceOperation(operation, operation.Messages[0].Action), serviceRegister) { string endpointAddress = endpoint.Address.Uri.ToString(); if (!endpointAddress.EndsWith("/")) endpointAddress = endpointAddress + "/"; this.operationUri = new Uri(endpointAddress + operation.Name); }
public RegisterServiceHosted(IServiceRegister serviceRegister, IServer server, IOptions <GrpcServerOptions> grpcServerOptions, IHostApplicationLifetime hostApplicationLifetime, ILogger <RegisterServiceHosted> logger) { _serviceRegister = serviceRegister; _server = server; _grpcServerOptions = grpcServerOptions.Value; _hostApplicationLifetime = hostApplicationLifetime; _logger = logger; }
/// <summary> /// Registers dependencies for this assembly /// </summary> public void RegisterDependencies(IServiceRegister serviceRegister) { if (serviceRegister is null) { throw new System.ArgumentNullException(nameof(serviceRegister)); } serviceRegister.Register <IViewRenderService, ViewRenderService>(ServiceLifetime.Scoped); }
/// <summary> /// Registers the dependencies /// </summary> public void RegisterDependencies(IServiceRegister serviceRegister) { if (serviceRegister is null) { throw new ArgumentNullException(nameof(serviceRegister)); } StaticLogger.Log($"Penguin.Persistence.DependencyInjection: {Assembly.GetExecutingAssembly().GetName().Version}", StaticLogger.LoggingLevel.Call); //if (!DependencyEngine.IsRegistered<PersistenceConnectionInfo>()) //{ //Wonky ass logic to support old EF connection strings from web.config. //Most of this can be removed when CE isn't needed. serviceRegister.Register((IServiceProvider ServiceProvider) => { if (!(ServiceProvider.GetService(typeof(IProvideConfigurations)) is IProvideConfigurations Configuration)) { throw new NullReferenceException("IProvideConfigurations must be registered before building database connection"); } string ConnectionString = Configuration.GetConnectionString("DefaultConnectionString"); if (ConnectionString is null) { string error = $"Can not find connection string {Strings.CONNECTION_STRING_NAME} in registered configuration provider"; try { throw new DatabaseNotConfiguredException(error, new MissingConfigurationException(Strings.CONNECTION_STRING_NAME, error )); } //Notify dev if possible catch (Exception) { return(new PersistenceConnectionInfo("", "")); } } string Provider = "System.Data.SqlClient"; if (ConnectionString.StartsWith("name=")) { ConnectionString = ConnectionString.Replace("name=", ""); ConnectionString = Configuration.GetConnectionString(ConnectionString); } PersistenceConnectionInfo connectionInfo = new PersistenceConnectionInfo(ConnectionString, Provider); if (connectionInfo.ProviderType == ProviderType.SQLCE) { connectionInfo.ProviderName = "System.Data.SqlServerCe.4.0"; } return(connectionInfo); }, ServiceLifetime.Singleton); }
public ApplicationStartup ReplaceServiceRegister(IServiceRegister serviceRegister) { if (this.IsStarted) { throw new FriendlyException("程序已启动,无法替换"); } this.ServiceRegister = serviceRegister; return(this); }
public override void Register(IServiceRegister register) { //Chain handling semantics are preferable on the client. //No reason multiple handlers should be consuming the same packets, complications things //Put it infront of the handling process if you want that functionality ChainMessageHandlerStrategy<TPeerType, TNetworkMessageType> chainHandler = new ChainMessageHandlerStrategy<TPeerType, TNetworkMessageType>(FindHandlersInScene()); //generics are semi-limited in .Net when trying to construct an instance of the type so we put the requirement for inheritors to create the instance. register.Register<THandlerServiceTypeConcrete>(CreateConcreteService(chainHandler), ComputeFlags(), typeof(THandlerServiceTypeServiceInterface)); }
/// <summary> /// Initializes a new instance of the <see cref="ClientJsonNetMessageFormatter"/> class. /// </summary> /// <param name="operation">The operation.</param> /// <param name="endpoint">The endpoint.</param> /// <param name="serializer">The serializer.</param> /// <param name="serviceRegister">The service register.</param> public ClientJsonNetMessageFormatter(OperationDescription operation, ServiceEndpoint endpoint, JsonSerializer serializer, IServiceRegister serviceRegister) : base(operation, endpoint, serviceRegister) { string endpointAddress = endpoint.Address.Uri.ToString(); if (!endpointAddress.EndsWith("/")) endpointAddress = endpointAddress + "/"; this.operationUri = new Uri(endpointAddress + operation.Name); this.serializer = serializer; }
public override void Register(IServiceRegister register) { //Chain handling semantics are preferable on the client. //No reason multiple handlers should be consuming the same packets, complications things //Put it infront of the handling process if you want that functionality ChainMessageHandlerStrategy <InstanceClientSession, IRequestMessage> chainHandler = new ChainMessageHandlerStrategy <InstanceClientSession, IRequestMessage>(FindHandlersInScene()); //generics are semi-limited in .Net when trying to construct an instance of the type so we put the requirement for inheritors to create the instance. register.Register <RequestMessageHandlerService <InstanceClientSession> >(new RequestMessageHandlerService <InstanceClientSession>(chainHandler), getFlags(), typeof(IRequestMessageHandlerService <InstanceClientSession>)); }
public ServiceRegisterFactory( IServiceRegister serviceRegister , IOptions <GrpcServerRegister> grpcServerRegisters ) { _serviceRegister = serviceRegister; _grpcServerRegisters = grpcServerRegisters.Value; }
public void RegisterDependencies(IServiceRegister serviceRegister) { if (serviceRegister is null) { throw new System.ArgumentNullException(nameof(serviceRegister)); } serviceRegister.Register(typeof(IUserSession), typeof(UserSession), ServiceLifetime.Scoped); serviceRegister.Register(typeof(UserSession), typeof(UserSession), ServiceLifetime.Scoped); }
//private readonly ServiceProtocol _protocol; /// <summary> 服务宿主机 </summary> /// <param name="serviceExecutor"></param> /// <param name="microListener"></param> /// <param name="serviceRegister"></param> /// <param name="entryFactory"></param> /// <param name="loggerFactory"></param> public MicroHost(IMicroExecutor serviceExecutor, IMicroListener microListener, IServiceRegister serviceRegister, IMicroEntryFactory entryFactory, ILoggerFactory loggerFactory) : base(serviceExecutor, microListener, loggerFactory) { _serviceRegister = serviceRegister; _entryFactory = entryFactory; _logger = loggerFactory.CreateLogger <MicroHost>(); //var protocol = microListener.GetType().GetCustomAttribute<ProtocolAttribute>(); //if (protocol != null) // _protocol = protocol.Protocol; }
public override void Initialize(IServiceRegister register) { base.Initialize(register); register.ScanWithDefaultConventions(this); register.RegisterJobs(this); register.RegisterMessageParsers(this); register.RegisterEventSubscribers(this); var modelRegister = ServiceLocator.Current.GetInstance<IModelRegistration>(); modelRegister.Register<PushoverFacadeContext>(); }
//We should try to locate this object in the scene public override void Register(IServiceRegister register) { //It should be in the scene hopefully LoginDetailsSceneData loginDetails = MonoBehaviour.FindObjectOfType <LoginDetailsSceneData>(); if (loginDetails == null) { throw new Exception($"{nameof(loginDetails)} of type {nameof(LoginDetailsSceneData)} could not be found in the scene."); } register.Register(loginDetails, getFlags(), typeof(ILoginDetails)); }
public void RegisterDependencies(IServiceRegister serviceRegister) { if (serviceRegister is null) { throw new ArgumentNullException(nameof(serviceRegister)); } foreach (Type workerType in TypeFactory.GetAllImplementations <IWorker>()) { serviceRegister.Register(workerType, workerType, ServiceLifetime.Scoped); } }
public void RegisterDependencies(IServiceRegister serviceRegister) { if (serviceRegister is null) { throw new ArgumentNullException(nameof(serviceRegister)); } foreach (Type controllerType in TypeFactory.GetDerivedTypes(typeof(Controller))) { serviceRegister.Register(controllerType, controllerType, ServiceLifetime.Scoped); } }
/// <summary> /// /// </summary> /// <param name="action"></param> /// <param name="parameters"></param> /// <param name="returnType"></param> /// <param name="serviceRegister"></param> protected MessageFormatter(string action, IEnumerable<ParameterInfo> parameters, Type returnType, IServiceRegister serviceRegister) { try { this.serviceRegister = serviceRegister; this.action = action; this.operationParameters = new List<OperationParameter> ( parameters.Select(n => new OperationParameter(n.Name, action, n.ParameterType, serviceRegister)) ); this.operationResult = new OperationResult(action, returnType, serviceRegister); } catch (Exception ex) { throw new ServiceOperationException("The service operation cannot be invoked because It uses an invalid object type, see innerException for details.", action, ex); } }
/// <summary> /// Initializes a new instance of the <see cref="QueryStringJsonConverter"/> class. /// </summary> /// <param name="serializer">The serializer.</param> /// <param name="serviceRegister">The service register.</param> public QueryStringJsonConverter(JsonSerializer serializer, IServiceRegister serviceRegister) { this.serializer = serializer; this.serviceRegister = serviceRegister; this.settings = serializer.MakeSettings(); }
public InterceptorRegistrator(IServiceRegister serviceRegister) { this.serviceRegister = serviceRegister; compositeInterceptor = new CompositeInterceptor(); }
/// <summary> /// /// </summary> /// <param name="serviceOperationInfo"></param> /// <param name="serviceRegister"></param> protected MessageFormatter(ServiceOperation serviceOperationInfo, IServiceRegister serviceRegister) : this(serviceOperationInfo.Action, serviceOperationInfo.Parameters, serviceOperationInfo.ReturnType, serviceRegister) { }
/// <summary> /// Initializes a new instance of the <see cref="DispatchJsonNetMessageFormatter"/> class. /// </summary> /// <param name="operation">The operation.</param> /// <param name="serializer">The serializer.</param> /// <param name="serviceRegister">The service register.</param> public DispatchJsonNetMessageFormatter(OperationDescription operation, JsonSerializer serializer, IServiceRegister serviceRegister) : base(operation, serviceRegister) { this.serializer = serializer; }
/// <summary> /// /// </summary> /// <param name="serviceRegister"></param> public OperationTypeBinder(IServiceRegister serviceRegister) { this.serviceRegister = serviceRegister; }
//: base (operation.Messages[1].Action, // operation.SyncMethod.GetParameters(), // operation.SyncMethod.ReturnType, // serviceRegister) /// <summary> /// /// </summary> /// <param name="operation"></param> /// <param name="serviceRegister"></param> protected DispatchJsonMessageFormatter(OperationDescription operation, IServiceRegister serviceRegister) : base(new ServiceOperation(operation, operation.Messages[1].Action), serviceRegister) { }