RegistrationBuilder

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

        public static IServiceCollection AddBewitGeneration<TPayload>(
            this IServiceCollection services,
            BewitOptions options)
        {
            return services.AddBewitGeneration(options, registrationBuilder =>
            {
                registrationBuilder.AddPayload<TPayload>();
            });
        }

        public static IServiceCollection AddBewitGeneration<TPayload>(
            this IServiceCollection services,
            BewitOptions options,
            Action<BewitRegistrationBuilder> build)
        {
            return services.AddBewitGeneration(options, registrationBuilder =>
            {
                registrationBuilder.AddPayload<TPayload>();
                build(registrationBuilder);
            });
        }


        public static IServiceCollection AddBewitUrlAuthorizationFilter(
            this IServiceCollection services,
            IConfiguration configuration,
            Action<BewitRegistrationBuilder> registrationBuilder,
            Action<BewitPayloadContext> payloadBuilder)
        {
            BewitOptions options = configuration.GetSection("Bewit").Get<BewitOptions>();
            return services.AddBewitUrlAuthorizationFilter(options, registrationBuilder, payloadBuilder);
        }

        public static IServiceCollection AddBewitFilter(
            this IServiceCollection services,
            IConfiguration configuration,
            Action<BewitRegistrationBuilder> registrationBuilder,
            Action<BewitPayloadContext> payloadBuilder)
        {
            BewitOptions options = configuration.GetSection("Bewit").Get<BewitOptions>();
            return services.AddBewitFilter(options, registrationBuilder, payloadBuilder);
        }


        public static IRegistrationBuilder<TLimit, ConcreteReflectionActivatorData, SingleRegistrationStyle> BlockImplicitCompositeOverride<TLimit>([NotNull] this IRegistrationBuilder<TLimit, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder) {
            return registrationBuilder.WithMetadata(BlockImplicitCompositeOverrideMetadataKey, true);
        }

        public static IRegistrationBuilder<TLimit, ConcreteReflectionActivatorData, SingleRegistrationStyle> ForceCompositeOverride<TLimit>([NotNull] this IRegistrationBuilder<TLimit, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder) {
            return registrationBuilder.WithMetadata(ForceCompositeOverrideMetadataKey, true);
        }


        public void RegisterInstance<TService, TImplementer>(TImplementer instance, string serviceName = null)
            where TService : class
            where TImplementer : class, TService
        {
            var registrationBuilder = ContainerBuilder.RegisterInstance(instance).As<TService>().SingleInstance();
            if (serviceName != null)
            {
                registrationBuilder.Named<TService>(serviceName);
            }
        }


        public void RegisterType<T>(string serviceName = null, LifeStyle lifeStyle = LifeStyle.Singleton)
        {
            var builder = _containerBuilder;
            var registrationBuilder = builder.RegisterType<T>().AsSelf();
            if (!string.IsNullOrWhiteSpace(serviceName))
            {
                registrationBuilder.Named<T>(serviceName);
            }
            registrationBuilder.SetLifeStyle(lifeStyle);
        }


    public void Register<TRegister>(RegisterOptions options = null)
        where TRegister : class
    {
      Register(typeof(TRegister), options);
    }

    public void Register(Type tRegister, RegisterOptions options = null)
    {
      _ = _builder.RegisterType(tRegister);
      IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder = _builder.RegisterType(tRegister);
      if (options != null)
      {
        switch (options.LifetimeScope)
        {
          case LifetimeScope.Singleton:
            _ = registrationBuilder.SingleInstance();
            break;
          case LifetimeScope.Scoped:
            _ = registrationBuilder.InstancePerLifetimeScope();
            break;
          case LifetimeScope.Transient:
            _ = registrationBuilder.InstancePerDependency();
            break;
        }
      }
    }

    public void Register<TRegister>(TRegister instance, RegisterOptions options = null)
        where TRegister : class
    {
      IRegistrationBuilder<TRegister, SimpleActivatorData, SingleRegistrationStyle> registrationBuilder = _builder.RegisterInstance(instance);
      if (options != null)
      {
        switch (options.LifetimeScope)
        {
          case LifetimeScope.Singleton:
            _ = registrationBuilder.SingleInstance();
            break;
          case LifetimeScope.Scoped:
            _ = registrationBuilder.InstancePerLifetimeScope();
            break;
          case LifetimeScope.Transient:
            _ = registrationBuilder.InstancePerDependency();
            break;
        }
      }
    }

    public void Register<TRegister, TResolve>(RegisterOptions options = null)
        where TResolve : TRegister
    {
      Register(typeof(TRegister), typeof(TResolve), options);
    }

    public void Register(Type tRegister, Type tResolve, RegisterOptions options = null)
    {
      IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder = _builder.RegisterType(tResolve).As(tRegister);
      if (options != null)
      {
        switch (options.LifetimeScope)
        {
          case LifetimeScope.Singleton:
            _ = registrationBuilder.SingleInstance();
            break;
          case LifetimeScope.Scoped:
            _ = registrationBuilder.InstancePerLifetimeScope();
            break;
          case LifetimeScope.Transient:
            _ = registrationBuilder.InstancePerDependency();
            break;
        }
      }
    }

    public void RegisterModule<TModule>()
        where TModule : IModule
    {
      ContainerBuilder moduleBuilder = new ContainerBuilder();
      _ = moduleBuilder.RegisterInstance<IRegistrar>(this);
      _ = moduleBuilder.RegisterType<TModule>();
      IContainer moduleContainer = moduleBuilder.Build();
      TModule module = moduleContainer.Resolve<TModule>();
      module.Initialize(this);
    }


        public virtual IDependencyRegistrationBuilder<TImplementation> As<TService>()
        {
            RegistrationBuilder.As<TService>();
            return this;
        }

        public virtual IDependencyRegistrationBuilder<TImplementation> As(Type type)
        {
            RegistrationBuilder.As(type);
            return this;
        }

        public virtual IDependencyRegistrationBuilder<TImplementation> AsScoped()
        {
            RegistrationBuilder.InstancePerLifetimeScope();
            return this;
        }

        public virtual IDependencyRegistrationBuilder<TImplementation> AsSelf()
        {
            RegistrationBuilder.As<TImplementation>();
            return this;
        }

        public virtual IDependencyRegistrationBuilder<TImplementation> AsSingleton()
        {
            RegistrationBuilder.SingleInstance();
            return this;
        }

        public virtual IDependencyRegistrationBuilder<TImplementation> AsTransient()
        {
            RegistrationBuilder.InstancePerDependency();
            return this;
        }



        public IContainerRegistrationRule RegisterType<TComponent>() where TComponent : class
        {
            var registrationBuilder = _builder.RegisterType<TComponent>();

            return CreateRegistrationRule(registrationBuilder);
        }

        public IContainerRegistrationRule RegisterType(Type componentType)
        {
            var registrationBuilder = _builder.RegisterType(componentType);

            return CreateRegistrationRule(registrationBuilder);
        }

        public IContainerRegistrationRule RegisterGeneric(Type componentType)
        {
            var registrationBuilder = _builder.RegisterGeneric(componentType);

            return CreateRegistrationRule(registrationBuilder);
        }

        public IContainerRegistrationRule RegisterInstance<TComponent>(TComponent componentInstance) where TComponent : class
        {
            var registrationBuilder = _builder.RegisterInstance(componentInstance);

            return CreateRegistrationRule(registrationBuilder);
        }

        public IContainerRegistrationRule RegisterFactory<TComponent>(Func<IContainerResolver, TComponent> componentFactory) where TComponent : class
        {
            var registrationBuilder = _builder.Register(r => componentFactory(r.Resolve<IContainerResolver>()));

            return CreateRegistrationRule(registrationBuilder);
        }


        private static IContainerRegistrationRule CreateRegistrationRule<TComponent, TActivatorData, TRegistrationStyle>(IRegistrationBuilder<TComponent, TActivatorData, TRegistrationStyle> registrationBuilder)
        {
            var aspectAttribute = typeof(TComponent).GetTypeInfo().GetCustomAttribute<AspectAttribute>();

            if (aspectAttribute!=null)
            {
                registrationBuilder.EnableInterfaceInterceptors()
                                   .InterceptedBy(typeof(InternalInterceptor<>).MakeGenericType(aspectAttribute.InterceptorType));
            }

            return new AutofacContainerRegistrationRule<TComponent, TActivatorData, TRegistrationStyle>(registrationBuilder);
        }


        public void UseCache<T>()
            where T: IDapperCache
        {
            services.AddTransient(typeof(IDapperCache), typeof(T));
        }

        public void Add<T>(DbConnectionOptions config)
            where T : DapperConnection, new()
        {
            services.AddScoped<T>(x =>
            {
                var underlyingConnection = config.DbConnectionFactory(x);
                var cache = x.GetService<IDapperCache>() ?? nullCache;

                var dapperConnection = new T();
                dapperConnection.SetDependencies(underlyingConnection, cache, config.CommandTimeout);

                return dapperConnection;
            });
        }

       public static void RegisterDapperEncapsulated(this IServiceCollection services, Action<RegistrationBuilder> builder)
       {
           var registrationBuilder = new RegistrationBuilder(services);
           builder(registrationBuilder);
       }

        private static IRegistrationBuilder<object, TActivatorData, TRegistrationStyle> ConfigureLifecycle<TActivatorData, TRegistrationStyle>(
             this IRegistrationBuilder<object, TActivatorData, TRegistrationStyle> registrationBuilder,
             ServiceLifetime lifecycleKind)
        {
            switch (lifecycleKind)
            {
                case ServiceLifetime.Singleton:
                    registrationBuilder.SingleInstance();
                    break;
                case ServiceLifetime.Scoped:
                    registrationBuilder.InstancePerLifetimeScope();
                    break;
                case ServiceLifetime.Transient:
                    registrationBuilder.InstancePerDependency();
                    break;
            }

            return registrationBuilder;
        }

        public static void Register(
                ContainerBuilder builder,
                IServiceCollection services)
        {
            foreach (var service in services)
            {
                if (service.ImplementationType != null)
                {
                    var serviceTypeInfo = service.ServiceType.GetTypeInfo();
                    if (serviceTypeInfo.IsGenericTypeDefinition)
                    {
                        builder
                            .RegisterGeneric(service.ImplementationType)
                            .As(service.ServiceType)
                            .ConfigureLifecycle(service.Lifetime)
                            .ConfigureConventions();
                    }
                    else
                    {
                        builder
                            .RegisterType(service.ImplementationType)
                            .As(service.ServiceType)
                            .ConfigureLifecycle(service.Lifetime)
                            .ConfigureConventions();
                    }
                }
                else if (service.ImplementationFactory != null)
                {
                    var registration = RegistrationBuilder.ForDelegate(service.ServiceType, (context, parameters) =>
                    {
                        var serviceProvider = context.Resolve<IServiceProvider>();
                        return service.ImplementationFactory(serviceProvider);
                    })
                    .ConfigureLifecycle(service.Lifetime)
                    .CreateRegistration();

                    builder.RegisterComponent(registration);
                }
                else
                {
                    builder
                        .RegisterInstance(service.ImplementationInstance)
                        .As(service.ServiceType)
                        .ConfigureLifecycle(service.Lifetime);
                }
            }
        }

        private static IRegistrationBuilder<object, TActivatorData, TRegistrationStyle> ConfigureConventions<TActivatorData, TRegistrationStyle>(
            this IRegistrationBuilder<object, TActivatorData, TRegistrationStyle> registrationBuilder)
        {            
            return registrationBuilder.PropertiesAutowired();
        }

Autofac.Builder.RegistrationBuilder : Object

Methods :

public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationStyle> ForDelegate(Func<IComponentContext, IEnumerable<Parameter>, T> delegate = )
public static IRegistrationBuilder<Object, SimpleActivatorData, SingleRegistrationStyle> ForDelegate(Type limitType = , Func<IComponentContext, IEnumerable<Parameter>, Object> delegate = )
public static IRegistrationBuilder<TImplementer, ConcreteReflectionActivatorData, SingleRegistrationStyle> ForType()
public static IRegistrationBuilder<Object, ConcreteReflectionActivatorData, SingleRegistrationStyle> ForType(Type implementationType = )
public static IComponentRegistration CreateRegistration(IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> builder = )
public static IComponentRegistration CreateRegistration(Guid id = , RegistrationData data = , IInstanceActivator activator = , IResolvePipelineBuilder pipelineBuilder = , Service[] services = )
public static IComponentRegistration CreateRegistration(Guid id = , RegistrationData data = , IInstanceActivator activator = , IResolvePipelineBuilder pipelineBuilder = , Service[] services = , IComponentRegistration target = )
public static Void RegisterSingleComponent(IComponentRegistryBuilder cr = , IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> builder = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()