コード例 #1
0
        private void Register(ServiceDescriptor descriptor)
        {
            _services.ExchangeValue(services =>
            {
                ServiceDescriptor desc;
                if (!services.TryGetValue(descriptor.ServiceType, out desc))
                {
                    return(services.Add(descriptor.ServiceType, descriptor));
                }

                descriptor.Next = desc;
                return(services.SetItem(descriptor.ServiceType, descriptor));
            });
        }
コード例 #2
0
 private void Purge(int sessionId)
 {
     _scopes.ExchangeValue(scopes =>
     {
         foreach (var entry in scopes.Values)
         {
             var name = entry.Domain.Name;
             var e    = entry.Purge(sessionId);
             if (e == null)
             {
                 scopes = scopes.Remove(name);
             }
             else if (e != entry)
             {
                 scopes = scopes.SetItem(name, e);
             }
         }
         return(scopes);
     });
 }
コード例 #3
0
        public async Task Can_exchange_value()
        {
            var safeLazy = new ThreadSafeLazyRef<string>(() => "");
            var tasks = new List<Task>();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(Task.Run(() => safeLazy.ExchangeValue(s => s + "s")));
            }

            await Task.WhenAll(tasks);

            Assert.Equal("ssssssssss", safeLazy.Value);
        }
コード例 #4
0
        public async Task Can_exchange_value()
        {
            var safeLazy = new ThreadSafeLazyRef <string>(() => "");
            var tasks    = new List <Task>();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(Task.Run(() => safeLazy.ExchangeValue(s => s + "s")));
            }

            await Task.WhenAll(tasks);

            Assert.Equal("ssssssssss", safeLazy.Value);
        }
コード例 #5
0
        private TService ResolveService <TService>(ServiceDescriptor desc) where TService : class
        {
            if (desc.Lifecycle == ServiceLifecycle.Singleton && _parent != null)
            {
                return(_parent.ResolveService <TService>(desc));
            }
            else if (desc.Lifecycle == ServiceLifecycle.Transient)
            {
                return((TService)desc.Create(this)); // TODO disposable
            }

            _resolvedServices.ExchangeValue(services =>
            {
                if (!services.ContainsKey(desc))
                {
                    return(services.Add(desc, desc.Create(this)));
                }
                return(services);
            });

            return((TService)_resolvedServices.Value[desc]);
        }
コード例 #6
0
 internal void Create(InternalEntityEntry entry)
 {
     _rows.ExchangeValue(rs => rs.Add(entry.GetPrimaryKeyValue(), entry.GetValueBuffer()));
 }
コード例 #7
0
 internal void Create(StateEntry stateEntry)
 {
     _rows.ExchangeValue(rs => rs.Add(stateEntry.GetPrimaryKeyValue(), stateEntry.GetValueBuffer()));
 }
コード例 #8
0
 internal void Create(IUpdateEntry entry)
 {
     _rows.ExchangeValue(rs => rs.Add(entry.GetPrimaryKeyValue(), CreateValueBuffer(entry)));
 }