示例#1
0
        /// <summary>
        /// Gets locks on the required <c>object</c> from the specified <c>resolver</c>.
        /// </summary>
        /// <typeparam name="T">Type of target <c>object</c>.</typeparam>
        /// <param name="resolver">Resolver that should be used.</param>
        /// <param name="name">Name of registration.</param>
        /// <returns>Temp <c>lock</c> on the <c>object</c>.</returns>
        public static async ValueTask <IxLock <T> > Get <T>(this IIxResolver resolver, string name = null)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            return(new IxLock <T>(await resolver.Resolve(new IxIdentifier(typeof(T), name))));
        }
示例#2
0
        /// <summary>
        /// Resolves instance just to instantiate it.
        /// </summary>
        /// <remarks>
        /// In many cases this method should be replaced by https://github.com/dmitriyse/ClrCoder/issues/8 (Auto activateion).
        /// </remarks>
        /// <typeparam name="T">Type of target <c>object</c>.</typeparam>
        /// <param name="resolver">Resolver that should be used.</param>
        /// <param name="name">Name of registration.</param>
        /// <returns>Async execution TPL task.</returns>
        public static async Task WarmUp <T>(this IIxResolver resolver, string name = null)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            using (await resolver.Resolve(new IxIdentifier(typeof(T), name)))
            {
                // Do nothing.
            }
        }
示例#3
0
        /// <summary>
        /// Gets locks on the required <c>object</c> from the specified <c>resolver</c>.
        /// </summary>
        /// <typeparam name="T">Type of target <c>object</c>.</typeparam>
        /// <typeparam name="TArg1">The type of the argument for current resolve operation.</typeparam>
        /// <param name="resolver">Resolver that should be used.</param>
        /// <param name="name">Name of registration.</param>
        /// <param name="arg1">The argument for current resolve operation.</param>
        /// <returns>Temp <c>lock</c> on the <c>object</c>.</returns>
        public static async ValueTask <IxLock <T> > Get <T, TArg1>(
            this IIxResolver resolver,
            [CanBeNull] string name,
            TArg1 arg1)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            return(new IxLock <T>(
                       await resolver.Resolve(
                           new IxIdentifier(typeof(T), name),
                           new Dictionary <IxIdentifier, object>
            {
                { new IxIdentifier(typeof(TArg1)), arg1 }
            })));
        }
示例#4
0
        /// <summary>
        /// Temporary solution for cluster references, until full support will be implemented in the IndirectX.
        /// </summary>
        /// <typeparam name="T">The type of the reference target.</typeparam>
        /// <param name="resolver">The IndirectX resolver.</param>
        /// <param name="clusterRef">The reference to resolve.</param>
        /// <returns>Lock on accessor proxy to the reference target.</returns>
        public static IxLock <T> ClusterGet <T>(this IIxResolver resolver, IClusterRef <T> clusterRef)
            where T : class
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            if (clusterRef == null)
            {
                throw new ArgumentNullException(nameof(clusterRef));
            }

            var runtimeRef = clusterRef as RuntimeLocalRef <T>;

            if (runtimeRef == null)
            {
                throw new NotImplementedException();
            }

            return(new IxLock <T>(runtimeRef.Target));
        }
示例#5
0
        // [Require(typeof(IClusterNode))]
        private LoggerWebApp(
            IIxResolver resolver,
            IWebHostBuilder webHostBuilder,
            IJsonLogger logger,
            ILogReader logReader,
            LoggerWebAppConfig config)
        {
            Log = new ClassJsonLogger <LoggerWebApp>(logger);

            Log.Info(_ => _("Starting Asp.Net core..."));
            _webHost = webHostBuilder

                       // Should be removed after adoption IndirectX to Asp.Net core.
                       .ConfigureServices(
                x => x
                .AddHttpRequestScopeService()
                .AddScopedHttpContextAccessor()
                .AddSingleton(new Tuple <IJsonLogger, IIxResolver>(Log, resolver))
                .AddSingleton <ILogReader>(logReader)
                .AddSingleton(config))
                       .UseStartup <LoggerWebAppStartup>()
                       .ConfigureJsonFormatters(JsonDefaults.RestRpcSerializerSource.Settings)
                       .Build();
            _webHost.Start();

            var addressesFeature = _webHost.ServerFeatures.Get <IServerAddressesFeature>();
            var addresses        = new HashSetEx <string>();

            foreach (string addressesFeatureAddress in addressesFeature.Addresses)
            {
                addresses.Add(addressesFeatureAddress);
                Log.Info(
                    addressesFeatureAddress,
                    (_, addr) => _($"Now listening on: {addr}").Data(new { ListenAddress = addr }));
            }

            HostingUrls = addresses;
        }
 public WebAppHttpScopeBinderMiddleware(IIxResolver resolver, RequestDelegate next)
 {
     _resolver = resolver;
     _next     = next;
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestScope"/> class.
 /// </summary>
 /// <param name="self">Container agent object to control this instance.</param>
 /// <param name="resolver">The resolver for dependencies of this scope.</param>
 /// <param name="context">The http context of the request of this scope.</param>
 public HttpRequestScope(IIxSelf self, IIxResolver resolver, HttpContext context)
 {
     _self    = self;
     Resolver = resolver;
     Context  = context;
 }
 public static IApplicationBuilder UseRequestScope(this IApplicationBuilder builder, IIxResolver resolver)
 {
     builder.UseMiddleware <WebAppHttpScopeBinderMiddleware>(resolver);
     return(builder);
 }