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)); }); }
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); }); }
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); }
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); }
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]); }
internal void Create(InternalEntityEntry entry) { _rows.ExchangeValue(rs => rs.Add(entry.GetPrimaryKeyValue(), entry.GetValueBuffer())); }
internal void Create(StateEntry stateEntry) { _rows.ExchangeValue(rs => rs.Add(stateEntry.GetPrimaryKeyValue(), stateEntry.GetValueBuffer())); }
internal void Create(IUpdateEntry entry) { _rows.ExchangeValue(rs => rs.Add(entry.GetPrimaryKeyValue(), CreateValueBuffer(entry))); }