/// <summary> 注册 </summary> /// <param name="resolver"></param> /// <param name="value"></param> /// <param name="key"></param> public static void Register(this IResolver resolver, object value, object key = null) { resolver.Register(value.GetType(), value, key); var interFaces = value.GetType().GetTypeInfo().GetInterfaces(); foreach (var interFace in interFaces) { resolver.Register(interFace, value, key); } }
private static void InternalRegister(bool registration) { if (ArgillaSettings.Current.Node == null) { return; } RegisterRequest registerRequest = new RegisterRequest() { ServiceName = ArgillaSettings.Current.Node.ServiceName, EndpointSync = ArgillaSettings.Current.Node.EndpointSync, EndpointAsync = ArgillaSettings.Current.Node.EndpointAsync }; try { RegisterResponse registerResponse = registration ? resolver.Register(registerRequest) : resolver.Unregister(registerRequest); if (registerResponse == null || !registerResponse.Success) { Manage(new RegistrationException(String.Format("Cannot {1} service \"{0}\"", registerRequest.ServiceName, (registration ? "register" : "unregister")))); } } catch (Exception e) { if (e.InnerException != null) { Manage(new RegistrationException(String.Format("Cannot {1} service \"{0}\"", registerRequest.ServiceName, (registration ? "register" : "unregister")))); } logger.Error(e, e.Message); } }
private CommandBase Resolve(Type command) { var instance = _resolver.Resolve(command); if (instance == null && _autoRegister) { _resolver.Register(command); instance = _resolver.Resolve(command); } return((CommandBase)instance); }
public object Create(Type type, object key = null) { var instance = _resolver.Resolve(type, key); if (instance != null) { return(instance); } instance = _proxyGenerator.CreateProxy(type, typeof(ProxyExecutor), _proxyProvider, key); _resolver.Register(type, instance, key); return(instance); }
/// <summary> /// Generic version of type registration /// </summary> /// <param name="resolver">Resolver.</param> /// <param name="factory">Factory.</param> /// <param name="lifetime">Lifetime.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static void Register <T>(this IResolver resolver, Func <IResolver, T> factory, Lifetime lifetime = Lifetime.Transient) { resolver.Register(typeof(T), (r) => { return((T)factory(r)); }, lifetime); }
/// <summary> /// Generic version of type registration. /// </summary> /// <param name="resolver">Resolver.</param> /// <param name="singleton">Singleton.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static void Register <T>(this IResolver resolver, T singleton) { resolver.Register(typeof(T), singleton); }
/// <summary> /// Generic version of type registration /// </summary> /// <typeparam name="T1"></typeparam> /// <typeparam name="T2"></typeparam> /// <param name="resolver"></param> /// <param name="lifetime"></param> public static void Register <T1, T2>(this IResolver resolver, Lifetime lifetime = Lifetime.Transient) { resolver.Register(typeof(T1), typeof(T2), lifetime); }
public void Register <TCommand>(IResolver resolver) where TCommand : CommandBase { resolver.Register <TCommand>(); Register <TCommand>(); }
public void Register <TInterface>(TInterface instance) where TInterface : class { _resolver.Register(instance); }