/// <summary> /// Initializes a new instance of the <see cref="ComponentRegistration"/> class. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="pipelineBuilder">The resolve pipeline builder for the registration.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="options">The additional registration options.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IResolvePipelineBuilder pipelineBuilder, IEnumerable <Service> services, IDictionary <string, object?> metadata, RegistrationOptions options = RegistrationOptions.None) { if (services == null) { throw new ArgumentNullException(nameof(services)); } Id = id; Activator = activator ?? throw new ArgumentNullException(nameof(activator)); Lifetime = lifetime ?? throw new ArgumentNullException(nameof(lifetime)); Sharing = sharing; Ownership = ownership; _lateBuildPipeline = pipelineBuilder; Services = Enforce.ArgumentElementNotNull(services, nameof(services)); Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); Options = options; }
private static (RegistrationMode mode, bool valid) ConvertFromLifetime(IComponentLifetime lifetime, InstanceSharing sharing) { var instancePerDependency = lifetime is CurrentScopeLifetime && sharing == InstanceSharing.None; if (instancePerDependency) { return(RegistrationMode.InstancePerUse, true); } var singleInstance = lifetime is RootScopeLifetime && sharing == InstanceSharing.Shared; if (singleInstance) { return(RegistrationMode.Singleton, true); } var asMatchingScopeLifetime = lifetime as MatchingScopeLifetime; var instancePerRequest = sharing == InstanceSharing.Shared && asMatchingScopeLifetime?.TagsToMatch.All(ttm => ttm == MatchingScopeLifetimeTags.RequestLifetimeScopeTag) == true; if (instancePerRequest) { return(RegistrationMode.InstancePerHttpRequest, true); } var instancePerLifetimeScope = lifetime is CurrentScopeLifetime && sharing == InstanceSharing.Shared; if (instancePerLifetimeScope) { return(default(RegistrationMode), false); } return(default(RegistrationMode), false); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata) { if (activator == null) { throw new ArgumentNullException(nameof(activator)); } if (lifetime == null) { throw new ArgumentNullException(nameof(lifetime)); } if (services == null) { throw new ArgumentNullException(nameof(services)); } if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } Id = id; Activator = activator; Lifetime = lifetime; Sharing = sharing; Ownership = ownership; Services = Enforce.ArgumentElementNotNull(services, nameof(services)).ToList(); Metadata = new Dictionary <string, object>(metadata); }
public ComponentRegistrationLifetimeDecorator(IComponentRegistration inner, IComponentLifetime lifetime) { if (inner == null) throw new ArgumentNullException("inner"); if (lifetime == null) throw new ArgumentNullException("lifetime"); _inner = inner; _lifetime = lifetime; }
public ComponentRegistration(Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata) { this.Id = id; this.Activator = Enforce.ArgumentNotNull <IInstanceActivator>(activator, "activator"); this.Lifetime = Enforce.ArgumentNotNull <IComponentLifetime>(lifetime, "lifetime"); this.Sharing = sharing; this.Ownership = ownership; this.Services = Enforce.ArgumentElementNotNull <IEnumerable <Service> >(Enforce.ArgumentNotNull <IEnumerable <Service> >(services, "services"), "services").ToList <Service>(); this.Metadata = new Dictionary <string, object>(Enforce.ArgumentNotNull <IDictionary <string, object> >(metadata, "metadata")); }
public static IComponentRegistration CreateRegistration(IEnumerable<Service> services, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing) { return new ComponentRegistration( Guid.NewGuid(), activator, lifetime, sharing, InstanceOwnership.OwnedByLifetimeScope, services, NoMetadata); }
public OpenGenericRegistrationSource( IServiceWithType genericService, Type implementorType, IComponentLifetime lifetime, InstanceSharing sharing) { this.genericService = genericService; this.implementorType = implementorType; this.lifetime = lifetime; this.sharing = sharing; }
/// <summary> /// Initializes a new instance of the <see cref="ComponentRegistration"/> class. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="options">Contains options for the registration.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object?> metadata, RegistrationOptions options = RegistrationOptions.None) : this(id, activator, lifetime, sharing, ownership, new ResolvePipelineBuilder(PipelineType.Registration), services, metadata, options) { }
/// <summary> /// Initializes a new instance of the <see cref="System.Object" /> /// class. /// </summary> // ReSharper disable once UnusedMember.Global public ComponentRegistration( IComponentLifetime lifetime , InstanceSharing sharing , InstanceOwnership ownership , IComponentRegistration target ) { Id = Guid.NewGuid( ); Lifetime = lifetime; Sharing = sharing; Ownership = ownership; Target = target; }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="target">The component registration upon which this registration is based.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata, IComponentRegistration target) : this(id, activator, lifetime, sharing, ownership, services, metadata) { _target = Enforce.ArgumentNotNull(target, "target"); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="target">The component registration upon which this registration is based.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable<Service> services, IDictionary<string, object> metadata, IComponentRegistration target) : this(id, activator, lifetime, sharing, ownership, services, metadata) { _target = target;// Enforce.ArgumentNotNull(target, "target"); }
public ComponentRegistrationLifetimeDecorator(IComponentRegistration inner, IComponentLifetime lifetime) { if (inner == null) { throw new ArgumentNullException("inner"); } if (lifetime == null) { throw new ArgumentNullException("lifetime"); } this._inner = inner; this._lifetime = lifetime; }
private static IComponentLifetime GetLifetime(IComponentLifetime lifetime) { if (lifetime.GetType() == typeof(CurrentScopeLifetime)) { return(new CurrentScopeLifetime()); } if (lifetime.GetType() == typeof(RootScopeLifetime)) { return(new RootScopeLifetime()); } throw new NotSupportedException($"Lifetime scope '${lifetime.GetType().Name}' is not supported."); }
public ComponentRegistrationLifetimeDecorator(IComponentRegistration inner, IComponentLifetime lifetime) { if (inner == null) { throw new ArgumentNullException(nameof(inner)); } if (lifetime == null) { throw new ArgumentNullException(nameof(lifetime)); } _inner = inner; Lifetime = lifetime; }
public ComponentHostedService(IComponentLifetime componentLifetime, IHostingEnvironment hostingEnvironment, IOptionAccessor <ApplicationOptions> optionAccessor) { _componentLifetime = componentLifetime ?? throw new ArgumentNullException(nameof(componentLifetime)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _applicationOptions = optionAccessor.Value; if (string.IsNullOrEmpty(_applicationOptions.ApplicationName)) { _applicationOptions.ApplicationName = _hostingEnvironment.ApplicationName; } if (string.IsNullOrEmpty(_applicationOptions.Environment)) { _applicationOptions.Environment = _hostingEnvironment.EnvironmentName; } }
public LifetimeModel GetLifetimeModel(IComponentLifetime lifetime) { if (lifetime == null) throw new ArgumentNullException("lifetime"); if (lifetime is CurrentScopeLifetime) return LifetimeModel.CurrentScope; if (lifetime is RootScopeLifetime) return LifetimeModel.RootScope; if (lifetime is MatchingScopeLifetime) return LifetimeModel.MatchingScope; return LifetimeModel.Other; }
public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, params Service[] services) { Id = id; Activator = activator; Lifetime = lifetime; Sharing = sharing; Services = services.ToArray(); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="target">The component registration upon which this registration is based.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata, IComponentRegistration target) : this(id, activator, lifetime, sharing, ownership, services, metadata) { if (target == null) { throw new ArgumentNullException(nameof(target)); } _target = target; }
/// <summary> /// Initializes a new instance of the <see cref="ComponentRegistration"/> class. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="pipelineBuilder">The resolve pipeline builder for the registration.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="target">The component registration upon which this registration is based.</param> /// <param name="options">Registration options.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IResolvePipelineBuilder pipelineBuilder, IEnumerable <Service> services, IDictionary <string, object?> metadata, IComponentRegistration target, RegistrationOptions options = RegistrationOptions.None) : this(id, activator, lifetime, sharing, ownership, pipelineBuilder, services, metadata, options) { _target = target ?? throw new ArgumentNullException(nameof(target)); // Certain flags carry over from the target. Options = options | (_target.Options & OptionsCopiedFromTargetRegistration); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata) { Id = id; Activator = Enforce.ArgumentNotNull(activator, "activator"); Lifetime = Enforce.ArgumentNotNull(lifetime, "lifetime"); Sharing = sharing; Ownership = ownership; Services = Enforce.ArgumentElementNotNull( Enforce.ArgumentNotNull(services, "services"), "services").ToList(); Metadata = new Dictionary <string, object>( Enforce.ArgumentNotNull(metadata, "metadata")); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable<Service> services, IDictionary<string, object> metadata) { Id = id; Activator = Enforce.ArgumentNotNull(activator, "activator"); Lifetime = Enforce.ArgumentNotNull(lifetime, "lifetime"); Sharing = sharing; Ownership = ownership; Services = Enforce.ArgumentElementNotNull( Enforce.ArgumentNotNull(services, "services"), "services").ToList(); Metadata = new Dictionary<string, object>( Enforce.ArgumentNotNull(metadata, "metadata")); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata) { Id = id; Activator = activator; // Enforce.ArgumentNotNull(activator, "activator"); Lifetime = lifetime; // Enforce.ArgumentNotNull(lifetime, "lifetime"); Sharing = sharing; Ownership = ownership; //var list = new List<Service>(services); //if (list.Contains(null)) //Enforce.ArgumentElementNotNull(services, "services"); Services = services; Metadata = metadata; //new Dictionary<string, object>(Enforce.ArgumentNotNull(metadata, "metadata")); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="id"></param> /// <param name="activator"></param> /// <param name="lifetime"></param> /// <param name="sharing"></param> /// <param name="ownership"></param> /// <param name="services"></param> /// <param name="metadata"></param> /// <param name="serviceDescriptor"></param> public ServiceDescriptorComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata, ServiceDescriptor serviceDescriptor) : base( id, activator, lifetime, sharing, ownership, services, metadata) { this.serviceDescriptor = serviceDescriptor ?? throw new ArgumentNullException(nameof(serviceDescriptor)); }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable<Service> services, IDictionary<string, object> metadata) { Id = id; Activator = activator;// Enforce.ArgumentNotNull(activator, "activator"); Lifetime = lifetime;// Enforce.ArgumentNotNull(lifetime, "lifetime"); Sharing = sharing; Ownership = ownership; //var list = new List<Service>(services); //if (list.Contains(null)) //Enforce.ArgumentElementNotNull(services, "services"); Services = services; Metadata = metadata;//new Dictionary<string, object>(Enforce.ArgumentNotNull(metadata, "metadata")); }
/// <summary> /// Initializes a new instance of the <see cref="System.Object" /> /// class. /// </summary> // ReSharper disable once UnusedMember.Global public ComponentRegistration( Guid id , IInstanceActivator activator , IComponentLifetime lifetime , InstanceSharing sharing , InstanceOwnership ownership , IEnumerable <Service> services , IDictionary <string, object> metadata , IComponentRegistration target ) { Id = id; Activator = activator; Lifetime = lifetime; Sharing = sharing; Ownership = ownership; Services = services; Metadata = metadata; Target = target; }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable<Service> services, IDictionary<string, object> metadata) { if (activator == null) throw new ArgumentNullException(nameof(activator)); if (lifetime == null) throw new ArgumentNullException(nameof(lifetime)); if (services == null) throw new ArgumentNullException(nameof(services)); if (metadata == null) throw new ArgumentNullException(nameof(metadata)); Id = id; Activator = activator; Lifetime = lifetime; Sharing = sharing; Ownership = ownership; Services = Enforce.ArgumentElementNotNull(services, nameof(services)).ToList(); Metadata = new Dictionary<string, object>(metadata); }
public ComponentRegistration( Service service, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing) { if (service == null) { throw new ArgumentNullException(nameof(service)); } if (activator == null) { throw new ArgumentNullException(nameof(activator)); } if (lifetime == null) { throw new ArgumentNullException(nameof(lifetime)); } Service = service; Activator = activator; Lifetime = lifetime; Sharing = sharing; }
public LifetimeModel GetLifetimeModel(IComponentLifetime lifetime) { if (lifetime == null) { throw new ArgumentNullException("lifetime"); } if (lifetime is CurrentScopeLifetime) { return(LifetimeModel.CurrentScope); } if (lifetime is RootScopeLifetime) { return(LifetimeModel.RootScope); } if (lifetime is MatchingScopeLifetime) { return(LifetimeModel.MatchingScope); } return(LifetimeModel.Other); }
/// <summary> /// Initializes a new instance of the <see cref="ScopeRestrictedRegisteredServicesTracker"/> class. /// </summary> /// <param name="restrictedRootScopeLifetime">The scope to which registrations are restricted.</param> internal ScopeRestrictedRegisteredServicesTracker(IComponentLifetime restrictedRootScopeLifetime) { _restrictedRootScopeLifetime = restrictedRootScopeLifetime; }
/// <summary> /// Create a new component registration. /// </summary> /// <param name="id">Unique identifier for the component.</param> /// <param name="activator">Activator used to activate instances.</param> /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param> /// <param name="sharing">Whether the component is shared within its lifetime scope.</param> /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param> /// <param name="services">Services the component provides.</param> /// <param name="metadata">Data associated with the component.</param> /// <param name="target">The component registration upon which this registration is based.</param> public ComponentRegistration( Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable<Service> services, IDictionary<string, object> metadata, IComponentRegistration target) : this(id, activator, lifetime, sharing, ownership, services, metadata) { if (target == null) throw new ArgumentNullException(nameof(target)); _target = target; }
public ScopeRestrictedRegistry(object scopeTag) { _restrictedRootScopeLifetime = new MatchingScopeLifetime(scopeTag); }
/// <summary> /// Initializes a new instance of the <see cref="ComponentRegistrationLifetimeDecorator"/> class. /// </summary> /// <param name="inner">The inner registration.</param> /// <param name="lifetime">The enforced lifetime.</param> public ComponentRegistrationLifetimeDecorator(IComponentRegistration inner, IComponentLifetime lifetime) { _inner = inner ?? throw new ArgumentNullException(nameof(inner)); Lifetime = lifetime ?? throw new ArgumentNullException(nameof(lifetime)); }
public ComponentHostedService(IComponentLifetime componentLifetime) { _componentLifetime = componentLifetime ?? throw new ArgumentNullException(nameof(componentLifetime)); }
public ScopeRestrictedRegistry(object scopeTag) { _restrictedRootScopeLifetime = new MatchingScopeLifetime(scopeTag); }
public ExternalComponentRegistration(Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object?> metadata, IComponentRegistration target, bool isAdapterForIndividualComponent) : base(id, activator, lifetime, sharing, ownership, services, metadata, target, isAdapterForIndividualComponent) { }
public RegistrationData(Service defaultService) { _defaultService = defaultService; Lifetime = new CurrentLifetimeScope(); }
internal ScopeRestrictedRegistry(object scopeTag, IDictionary <string, object> properties) : base(properties) { _restrictedRootScopeLifetime = new MatchingScopeLifetime(scopeTag); }
public static IComponentRegistration CreateRegistration(IEnumerable <Service> services, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing) { return(new ComponentRegistration( Guid.NewGuid(), activator, lifetime, sharing, InstanceOwnership.OwnedByLifetimeScope, services, GetDefaultMetadata())); }