using System;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using VContainer.Diagnostics;
using VContainer.Internal;
namespace VContainer
{
public interface IObjectResolver : IDisposable
{
object ApplicationOrigin { get; }
DiagnosticsCollector Diagnostics { get; set; }
///
/// Resolve from type
///
///
/// This version of resolve looks for all of scopes
///
object Resolve(Type type);
///
/// Try resolve from type
///
///
/// This version of resolve looks for all of scopes
///
/// Successfully resolved
bool TryResolve(Type type, out object resolved);
///
/// Resolve from meta with registration
///
///
/// This version of resolve will look for instances from only the registration information already founds.
///
object Resolve(Registration registration);
IScopedObjectResolver CreateScope(Action installation = null);
void Inject(object instance);
bool TryGetRegistration(Type type, out Registration registration);
}
public interface IScopedObjectResolver : IObjectResolver
{
IObjectResolver Root { get; }
IScopedObjectResolver Parent { get; }
}
public enum Lifetime
{
Transient,
Singleton,
Scoped
}
public sealed class ScopedContainer : IScopedObjectResolver
{
public IObjectResolver Root { get; }
public IScopedObjectResolver Parent { get; }
public object ApplicationOrigin { get; }
public DiagnosticsCollector Diagnostics { get; set; }
readonly Registry registry;
readonly ConcurrentDictionary> sharedInstances = new ConcurrentDictionary>();
readonly CompositeDisposable disposables = new CompositeDisposable();
readonly Func> createInstance;
internal ScopedContainer(
Registry registry,
IObjectResolver root,
IScopedObjectResolver parent = null,
object applicationOrigin = null)
{
Root = root;
Parent = parent;
ApplicationOrigin = applicationOrigin;
this.registry = registry;
createInstance = registration =>
{
return new Lazy