/// <summary> /// Registers a transient service of the type specified in <typeparamref name="TService"/> to the /// specified <see cref="IServiceRegistration"/>. /// </summary> /// <typeparam name="TService">The type of the service to add.</typeparam> /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Transient"/> public static IServiceRegistration RegisterTransient <TService>(this IServiceRegistration services) where TService : class { if (services == null) { throw new ArgumentNullException(nameof(services)); } return(services.RegisterTransient(typeof(TService))); }
/// <summary> /// Registers a transient service of the type specified in <paramref name="serviceType"/> to the /// specified <see cref="IServiceRegistration"/>. /// </summary> /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param> /// <param name="serviceType">The type of the service to register and the implementation to use.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Transient"/> public static IServiceRegistration RegisterTransient(this IServiceRegistration services, Type serviceType) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } return(services.RegisterTransient(serviceType, serviceType)); }
/// <summary> /// Registers a transient service of the type specified in <typeparamref name="TService"/> with a /// factory specified in <paramref name="implementationFactory"/> to the /// specified <see cref="IServiceRegistration"/>. /// </summary> /// <typeparam name="TService">The type of the service to add.</typeparam> /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param> /// <param name="implementationFactory">The factory that creates the service.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Transient"/> public static IServiceRegistration RegisterTransient <TService>(this IServiceRegistration services, Func <IServiceProvider, TService> implementationFactory) where TService : class { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (implementationFactory == null) { throw new ArgumentNullException(nameof(implementationFactory)); } return(services.RegisterTransient(typeof(TService), implementationFactory)); }
public void Register(IServiceRegistration services, IDictionary <string, object> data) { services.RegisterSingleton <IConnection, SampleConnection>(); services.RegisterTransient <IUserService, UserService>(c => new UserService(c.GetService <IConnection>())); services.RegisterSingleton(r => r .Types(t => t.AssignableTo(typeof(IReadOnlyRepository <>))) .As(s => s.Self().ImplementedInterfaces()) ); services.RegisterSingleton(r => r .Types(t => t.AssignableTo <IService>()) .As(s => s.Self().ImplementedInterfaces()) ); services.RegisterSingleton(r => r .Types(t => t.AssignableTo <IVehicle>()) .As(s => s.Self().ImplementedInterfaces()) ); }
public void Register(IServiceRegistration services, IDictionary <string, object> data) { services.RegisterSingleton <IConnection, SampleConnection>(); services.RegisterTransient <IUserService, UserService>(); }