RegistrationExtensions

Namespace: MassTransit
We found 10 examples in language CSharp for this search. You will see 34 fragments of code.

		/// <summary>
		/// Register the types in an assembly.
		/// </summary>
		/// <param name="assemblies">The assemblies from which to register types.</param>
		/// <returns>Registration builder allowing the registration to be configured.</returns>
		public IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle> RegisterAssemblyTypes(params Assembly[] assemblies)
		{
			return global::Autofac.RegistrationExtensions.RegisterAssemblyTypes(this, assemblies);
		}

		/// <summary>
		/// Add a component to the container.
		/// </summary>
		/// <param name="registration">The component to add.</param>
		public void RegisterComponent(IComponentRegistration registration)
		{
			global::Autofac.RegistrationExtensions.RegisterComponent(this, registration);
		}

		/// <summary>
		/// Add a module to the container.
		/// </summary>
		/// <typeparam name="TModule">The module to add.</typeparam>
		public void RegisterModule<TModule>() where TModule : IModule, new()
		{
			global::Autofac.RegistrationExtensions.RegisterModule<TModule>(this);
		}

		/// <summary>
		/// Add a module to the container.
		/// </summary>
		/// <param name="module">The module to add.</param>
		public void RegisterModule(IModule module)
		{
			global::Autofac.RegistrationExtensions.RegisterModule(this, module);
		}

		/// <summary>
		/// Add a registration source to the container.
		/// </summary>
		/// <param name="registrationSource">The registration source to add.</param>
		public void RegisterSource(IRegistrationSource registrationSource)
		{
			global::Autofac.RegistrationExtensions.RegisterSource(this, registrationSource);
		}

        /// <summary>
        /// Registers the library with the bootstrapper.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper.</param>
        /// <returns>The bootstrapper</returns>
        public static ICanisterConfiguration? RegisterHolmes(this ICanisterConfiguration? bootstrapper)
        {
            return bootstrapper?.AddAssembly(typeof(RegistrationExtensions).Assembly)
                                .RegisterSQLHelper();
        }


        public void AddComponent(Type service, Type implementation, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.UpdateContainer((Action<ContainerBuilder>)(x =>
            {
                List<Type> list = new List<Type>()
        {
          service
        };
                if (service.IsGenericType)
                {
                    IRegistrationBuilder<object, ReflectionActivatorData, DynamicRegistrationStyle> registrationBuilder = ContainerManagerExtensions.PerLifeStyle<object, ReflectionActivatorData, DynamicRegistrationStyle>(RegistrationExtensions.RegisterGeneric(x, implementation).As(list.ToArray()), lifeStyle);
                    if (string.IsNullOrEmpty(key))
                        return;
                    registrationBuilder.Keyed((object)key, service);
                }
                else
                {
                    IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder = ContainerManagerExtensions.PerLifeStyle<object, ConcreteReflectionActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterType(x, implementation).As(list.ToArray()), lifeStyle);
                    if (!string.IsNullOrEmpty(key))
                        registrationBuilder.Keyed((object)key, service);
                }
            }));
        }

        public void AddComponent<TService, TImplementation>(string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponent(typeof(TService), typeof(TImplementation), key, lifeStyle);
        }

        public void AddComponent(Type service, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponent(service, service, key, lifeStyle);
        }

        public void AddComponent<TService>(string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponent<TService, TService>(key, lifeStyle);
        }

        public void AddComponentInstance<TService>(object instance, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponentInstance(typeof(TService), instance, key, lifeStyle);
        }

        public void AddComponentInstance(Type service, object instance, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.UpdateContainer((Action<ContainerBuilder>)(x => ContainerManagerExtensions.PerLifeStyle<object, SimpleActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterInstance<object>(x, instance).Keyed((object)key, service).As(new Type[1]
      {
        service
      }), lifeStyle)));
        }


        public void AddComponent(Type service, Type implementation, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.UpdateContainer((Action<ContainerBuilder>)(x =>
            {
                List<Type> list = new List<Type>()
        {
          service
        };
                if (service.IsGenericType)
                {
                    IRegistrationBuilder<object, ReflectionActivatorData, DynamicRegistrationStyle> registrationBuilder = ContainerManagerExtensions.PerLifeStyle<object, ReflectionActivatorData, DynamicRegistrationStyle>(RegistrationExtensions.RegisterGeneric(x, implementation).As(list.ToArray()), lifeStyle);
                    if (string.IsNullOrEmpty(key))
                        return;
                    registrationBuilder.Keyed((object)key, service);
                }
                else
                {
                    IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder = ContainerManagerExtensions.PerLifeStyle<object, ConcreteReflectionActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterType(x, implementation).As(list.ToArray()), lifeStyle);
                    if (!string.IsNullOrEmpty(key))
                        registrationBuilder.Keyed((object)key, service);
                }
            }));
        }

        public void AddComponent<TService, TImplementation>(string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponent(typeof(TService), typeof(TImplementation), key, lifeStyle);
        }

        public void AddComponent(Type service, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponent(service, service, key, lifeStyle);
        }

        public void AddComponent<TService>(string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponent<TService, TService>(key, lifeStyle);
        }

        public void AddComponentInstance<TService>(object instance, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.AddComponentInstance(typeof(TService), instance, key, lifeStyle);
        }

        public void AddComponentInstance(Type service, object instance, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
        {
            this.UpdateContainer((Action<ContainerBuilder>)(x => ContainerManagerExtensions.PerLifeStyle<object, SimpleActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterInstance<object>(x, instance).Keyed((object)key, service).As(new Type[1]
      {
        service
      }), lifeStyle)));
        }

        public static ILifetimeScope GetAutofacContainer(this IContainer container)
        {
            return (container as ObjectContainer)?._container;
        }

        public IContainer CreateChildContainer()
        {
            var scope = _container.BeginLifetimeScope();
            var container = new ObjectContainer(scope, this);
            return container;
        }

        public void Dispose()
        {
            if (!_disposed)
            {
                _disposed = true;
                _container.Dispose();
            }
        }

        public IContainer RegisterInstance(Type t, object instance, Lifetime lifetime = Lifetime.Singleton)
        {
            var builder = new ContainerBuilder();
            builder.RegisterInstance(instance)
                .As(t)
                .InstanceLifetime(lifetime);

            builder.Update(_container.ComponentRegistry);

            return this;
        }

        public IContainer RegisterInstance(Type t, string name, object instance, Lifetime lifetime = Lifetime.Singleton)
        {
            var builder = new ContainerBuilder();
            builder.RegisterInstance(instance)
                .Named(name, t)
                .InstanceLifetime(lifetime);
            builder.Update(_container.ComponentRegistry);
            return this;
        }

        public IContainer RegisterInstance<TInterface>(TInterface instance, Lifetime lifetime = Lifetime.Singleton)
            where TInterface : class
        {
            var builder = new ContainerBuilder();
            builder.RegisterInstance(instance)
                .InstanceLifetime(lifetime);
            builder.Update(_container.ComponentRegistry);
            return this;
        }

        /// <summary>
        /// Registers the library with the bootstrapper.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper.</param>
        /// <returns>The bootstrapper</returns>
        public static ICanisterConfiguration? RegisterSQLHelper(this ICanisterConfiguration? bootstrapper)
        {
            return bootstrapper?.AddAssembly(typeof(RegistrationExtensions).Assembly)
                                .RegisterBigBookOfDataTypes();
        }

        /// <summary>
        /// Registers the library with the bootstrapper.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper.</param>
        /// <returns>The bootstrapper</returns>
        public static ICanisterConfiguration? RegisterDataModeler(this ICanisterConfiguration? bootstrapper)
        {
            return bootstrapper?.AddAssembly(typeof(RegistrationExtensions).Assembly)
                                .RegisterSQLHelper();
        }

        [Fact]
        public void AsActionFilterForActionScopedFilterAddsCorrectMetadata()
        {
            AssertFilterRegistration<TestActionFilter, IActionFilter>(
                FilterScope.Action,
                TestController.GetAction1MethodInfo<TestController>(),
                r => r.AsActionFilterFor<TestController>(c => c.Action1(default), 20),
                AutofacFilterProvider.ActionFilterMetadataKey);
        }

        [Fact]
        public void AsActionFilterForActionScopedFilterThrowsExceptionForNullRegistration()
        {
            var exception = Assert.Throws<ArgumentNullException>(
                () => Autofac.Integration.Mvc.RegistrationExtensions.AsActionFilterFor<TestController>
                    (null, c => c.Action1(default)));

            Assert.Equal("registration", exception.ParamName);
        }

        [Fact]
        public void AsActionFilterForControllerScopedFilterAddsCorrectMetadata()
        {
            AssertFilterRegistration<TestActionFilter, IActionFilter>(
                FilterScope.Controller,
                null,
                r => r.AsActionFilterFor<TestController>(20),
                AutofacFilterProvider.ActionFilterMetadataKey);
        }

        [Fact]
        public void AsActionFilterForControllerScopedFilterThrowsExceptionForNullRegistration()
        {
            var exception = Assert.Throws<ArgumentNullException>(
                () => Autofac.Integration.Mvc.RegistrationExtensions.AsActionFilterFor<TestController>(null));

            Assert.Equal("registration", exception.ParamName);
        }

        [Fact]
        public void AsActionFilterForRequiresActionSelector()
        {
            var builder = new ContainerBuilder();
            var exception = Assert.Throws<ArgumentNullException>(
                () => builder.Register(c => new TestActionFilter()).AsActionFilterFor<TestController>(null));
            Assert.Equal("actionSelector", exception.ParamName);
        }

        [Fact]
        public void AsActionFilterForServiceTypeMustBeActionFilter()
        {
            var builder = new ContainerBuilder();

            var exception = Assert.Throws<ArgumentException>(
                () => builder.RegisterInstance(new object()).AsActionFilterFor<TestController>());

            Assert.Equal("registration", exception.ParamName);
        }

#pragma warning restore CS8618 // Non-nullable property 'Instance' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

        public static void RegisterSelf(this ContainerBuilder builder)
        {
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
            IContainer container = null;
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
#pragma warning disable CS8714 // The type 'Autofac.IContainer?' cannot be used as type parameter 'T' in the generic type or method 'RegistrationExtensions.Register<T>(ContainerBuilder, Func<IComponentContext, T>)'. Nullability of type argument 'Autofac.IContainer?' doesn't match 'notnull' constraint.
            builder.Register(c => container).AsSelf().SingleInstance();
#pragma warning restore CS8714 // The type 'Autofac.IContainer?' cannot be used as type parameter 'T' in the generic type or method 'RegistrationExtensions.Register<T>(ContainerBuilder, Func<IComponentContext, T>)'. Nullability of type argument 'Autofac.IContainer?' doesn't match 'notnull' constraint.
            builder.RegisterBuildCallback(c => container = (IContainer)c);
        }

using Microsoft.CodeAnalysis;
using System;
using System.Linq;

namespace Autofac.Analyzers
{
    public class AutofacTypeContext
    {
        const string ContainerBuilderName = "Autofac.ContainerBuilder";
        const string RegistrationExtensionsName = "Autofac.RegistrationExtensions";
        const string RegistrationBuilderInterfaceName = "Autofac.Builder.IRegistrationBuilder`3";

        private class ExtensionMethodName
        {
            public ExtensionMethodName(string simple, Func<IMethodSymbol> predicate = null)
            {
                Simple = simple;
                Predicate = predicate;
            }

            public string Simple { get; }

            public Func<IMethodSymbol> Predicate { get; }
        }

        private Lazy<INamedTypeSymbol> containerBuilderType;
        private Lazy<INamedTypeSymbol> registrationExtensionsType;
        private Lazy<INamedTypeSymbol> registrationBuilderInterface;
        private Lazy<IModuleSymbol> autofacModule;

        public AutofacTypeContext(Compilation compileContext)
        {
            containerBuilderType = new Lazy<INamedTypeSymbol>(() => compileContext.GetTypeByMetadataName(ContainerBuilderName));
            registrationExtensionsType = new Lazy<INamedTypeSymbol>(() => compileContext.GetTypeByMetadataName(RegistrationExtensionsName));
            registrationBuilderInterface = new Lazy<INamedTypeSymbol>(() => compileContext.GetTypeByMetadataName(RegistrationBuilderInterfaceName));
            autofacModule = new Lazy<IModuleSymbol>(() => ContainerBuilder.ContainingModule);
        }

        public INamedTypeSymbol ContainerBuilder => containerBuilderType.Value;

        public INamedTypeSymbol RegistrationExtensions => registrationExtensionsType.Value;

        public INamedTypeSymbol RegistrationBuilderInterface => registrationBuilderInterface.Value;

        public IModuleSymbol AutofacModule => autofacModule.Value;
    }
}

MassTransit.RegistrationExtensions : Object

Methods :

public static IConsumerRegistrationConfigurator<T> AddConsumer(IRegistrationConfigurator configurator = , Action<IConsumerConfigurator<T>> configure = null)
public static Void AddConsumers(IRegistrationConfigurator configurator = , Assembly[] assemblies = )
public static Void AddConsumers(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = , Assembly[] assemblies = )
public static Void AddConsumersFromNamespaceContaining(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = null)
public static Void AddConsumersFromNamespaceContaining(IRegistrationConfigurator configurator = , Type type = , Func<Type, Boolean> filter = null)
public static Void AddConsumers(IRegistrationConfigurator configurator = , Type[] types = )
public static Void AddConsumers(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = , Type[] types = )
public static ISagaRegistrationConfigurator<T> AddSaga(IRegistrationConfigurator configurator = , Action<ISagaConfigurator<T>> configure = null)
public static Void AddSagas(IRegistrationConfigurator configurator = , Assembly[] assemblies = )
public static Void AddSagasFromNamespaceContaining(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = null)
public static Void AddSagasFromNamespaceContaining(IRegistrationConfigurator configurator = , Type type = , Func<Type, Boolean> filter = null)
public static Void AddSagas(IRegistrationConfigurator configurator = , Type[] types = )
public static ISagaRegistrationConfigurator<T> AddSagaStateMachine(IRegistrationConfigurator configurator = , Action<ISagaConfigurator<T>> configure = null)
public static Void AddSagaStateMachines(IRegistrationConfigurator configurator = , Assembly[] assemblies = )
public static Void AddSagaStateMachinesFromNamespaceContaining(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = null)
public static Void AddSagaStateMachinesFromNamespaceContaining(IRegistrationConfigurator configurator = , Type type = , Func<Type, Boolean> filter = null)
public static Void AddSagaStateMachines(IRegistrationConfigurator configurator = , Type[] types = )
public static Void RegisterSagaStateMachines(IContainerRegistrar registrar = , Assembly[] assemblies = )
public static Void RegisterSagaStateMachines(IContainerRegistrar registrar = , Type[] types = )
public static IExecuteActivityRegistrationConfigurator<TActivity, TArguments> AddExecuteActivity(IRegistrationConfigurator configurator = , Action<IExecuteActivityConfigurator<TActivity, TArguments>> configure = null)
public static IActivityRegistrationConfigurator<TActivity, TArguments, TLog> AddActivity(IRegistrationConfigurator configurator = , Action<IExecuteActivityConfigurator<TActivity, TArguments>> configureExecute = null, Action<ICompensateActivityConfigurator<TActivity, TLog>> configureCompensate = null)
public static Void AddActivities(IRegistrationConfigurator configurator = , Assembly[] assemblies = )
public static Void AddActivitiesFromNamespaceContaining(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = null)
public static Void AddActivitiesFromNamespaceContaining(IRegistrationConfigurator configurator = , Type type = , Func<Type, Boolean> filter = null)
public static Void AddActivities(IRegistrationConfigurator configurator = , Type[] types = )
public static Void SetSnakeCaseEndpointNameFormatter(IRegistrationConfigurator configurator = )
public static Void SetKebabCaseEndpointNameFormatter(IRegistrationConfigurator configurator = )
public static IFutureRegistrationConfigurator<T> AddFuture(IRegistrationConfigurator configurator = )
public static IFutureRegistrationConfigurator<TFuture> AddFutureRequestConsumer(IRegistrationConfigurator configurator = , Action<IConsumerConfigurator<TConsumer>> configure = null)
public static Void AddFutures(IRegistrationConfigurator configurator = , Assembly[] assemblies = )
public static Void AddFutures(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = , Assembly[] assemblies = )
public static Void AddFuturesFromNamespaceContaining(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = null)
public static Void AddFuturesFromNamespaceContaining(IRegistrationConfigurator configurator = , Type type = , Func<Type, Boolean> filter = null)
public static Void AddFutures(IRegistrationConfigurator configurator = , Type[] types = )
public static Void AddFutures(IRegistrationConfigurator configurator = , Func<Type, Boolean> filter = , Type[] types = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods