/// <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); }
/// <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; }
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> /// 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> /// 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"); }
public IRegistrationBuilder SingleInstance() { #region Please implement the method /* * Please create a single instance registration. Please refer to * InstancePerDependency as an example. */ Lifetime = new RootScopeLifetime(); Sharing = InstanceSharing.Shared; return(this); #endregion }
public IRegistrationBuilder InstancePerLifetimeScope() { #region Please implement the method /* * Please create an instance per lifetime scope registration. Please refer to * InstancePerDependency as an example. */ Lifetime = new CurrentScopeLifetime(); Sharing = InstanceSharing.Shared; return(this); #endregion }
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> /// 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> /// <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> /// 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 IRegistrationBuilder InstancePerDependency() { Lifetime = new CurrentScopeLifetime(); Sharing = InstanceSharing.None; return(this); }
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 IRegistrationBuilder InstancePerLifetimeScope() { Lifetime = new CurrentScopeLifetime(); Sharing = InstanceSharing.Shared; return(this); }
public void WithInstanceScope_CheckLifetimeTranslation(TypeRegistrationLifetime entLibLifetime, InstanceSharing autofacInstanceSharing, Type autofacLifetimeType) { var builder = new ContainerBuilder(); builder.RegisterType<RegisteredServiceConsumer>().WithInstanceScope(entLibLifetime); var container = builder.Build(); IComponentRegistration autofacRegistration = null; Assert.IsTrue(container.ComponentRegistry.TryGetRegistration(new TypedService(typeof(RegisteredServiceConsumer)), out autofacRegistration), "The service type was not registered into the container."); Assert.IsInstanceOf(autofacLifetimeType, autofacRegistration.Lifetime, "The registration lifetime type was not correct."); Assert.AreEqual(autofacInstanceSharing, autofacRegistration.Sharing, "The registration sharing was not correct."); }
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())); }
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); }
internal static void AssertSharing <TComponent>(this IComponentContext context, InstanceSharing sharing) { var registration = context.RegistrationFor <TComponent>(); Assert.Equal(sharing, registration.Sharing); }
public void WithInstanceScope_CheckLifetimeTranslation(TypeRegistrationLifetime entLibLifetime, InstanceSharing autofacInstanceSharing, Type autofacLifetimeType) { var builder = new ContainerBuilder(); builder.RegisterType <RegisteredServiceConsumer>().WithInstanceScope(entLibLifetime); var container = builder.Build(); IComponentRegistration autofacRegistration = null; Assert.True(container.ComponentRegistry.TryGetRegistration(new TypedService(typeof(RegisteredServiceConsumer)), out autofacRegistration), "The service type was not registered into the container."); Assert.IsType(autofacLifetimeType, autofacRegistration.Lifetime); Assert.Equal(autofacInstanceSharing, autofacRegistration.Sharing); }
public IRegistrationBuilder SingleInstance() { Sharing = InstanceSharing.Shared; Lifetime = new RootScopeLifetime(); return(this); }
public static void AssertSharing <TComponent>(this IComponentContext context, InstanceSharing sharing) { var cr = context.RegistrationFor <TComponent>(); Assert.Equal(sharing, cr.Sharing); }
public SharingModel GetSharingModel(InstanceSharing sharing) { return (SharingModel) (int) sharing; }
/// <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 SharingModel GetSharingModel(InstanceSharing sharing) { return((SharingModel)(int)sharing); }
/// <summary> /// Asserts the current service type has been registered using the specified <see cref="InstanceSharing"/> on the current <see cref="IContainer"/>. /// </summary> /// <param name="sharing">The instance sharing mode</param> public RegistrationAssertions Shared(InstanceSharing sharing) { _registration.Sharing.Should().Be(sharing, $"Type '{Type}' should be shared as '{sharing}'"); return(this); }
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")); }