public void Configure(IDependencyRegister dependencyRegister) { dependencyRegister.AddSingleton <ISortService, QuickSortService>(); }
public static IDependencyRegister AddSingleton <TImplementation>(this IDependencyRegister register, Func <IDependencyResolver, TImplementation> instanceCreator) where TImplementation : class { return(register.AddSingleton <TImplementation, TImplementation>(instanceCreator)); }
public static IDependencyRegister AddRawRabbit(this IDependencyRegister register, RawRabbitOptions options = null) { register .AddSingleton(options?.ClientConfiguration ?? RawRabbitConfiguration.Local) .AddSingleton <IConnectionFactory, ConnectionFactory>(provider => { var cfg = provider.GetService <RawRabbitConfiguration>(); return(new ConnectionFactory { VirtualHost = cfg.VirtualHost, UserName = cfg.Username, Password = cfg.Password, Port = cfg.Port, HostName = cfg.Hostnames.FirstOrDefault() ?? string.Empty, AutomaticRecoveryEnabled = cfg.AutomaticRecovery, TopologyRecoveryEnabled = cfg.TopologyRecovery, NetworkRecoveryInterval = cfg.RecoveryInterval, ClientProperties = provider.GetService <IClientPropertyProvider>().GetClientProperties(cfg), Ssl = cfg.Ssl }); }) .AddSingleton <IChannelPoolFactory, AutoScalingChannelPoolFactory>() .AddSingleton(resolver => AutoScalingOptions.Default) .AddSingleton <IClientPropertyProvider, ClientPropertyProvider>() .AddSingleton <ISerializer>(resolver => new Serialization.JsonSerializer(new Newtonsoft.Json.JsonSerializer { TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, Formatting = Formatting.None, CheckAdditionalContent = true, ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }, ObjectCreationHandling = ObjectCreationHandling.Auto, DefaultValueHandling = DefaultValueHandling.Ignore, TypeNameHandling = TypeNameHandling.Auto, ReferenceLoopHandling = ReferenceLoopHandling.Serialize, MissingMemberHandling = MissingMemberHandling.Ignore, PreserveReferencesHandling = PreserveReferencesHandling.Objects, NullValueHandling = NullValueHandling.Ignore })) .AddSingleton <IConsumerFactory, ConsumerFactory>() .AddSingleton <IChannelFactory>(resolver => { var channelFactory = new ChannelFactory(resolver.GetService <IConnectionFactory>(), resolver.GetService <RawRabbitConfiguration>()); channelFactory .ConnectAsync() .ConfigureAwait(false) .GetAwaiter() .GetResult(); return(channelFactory); }) .AddSingleton <ISubscriptionRepository, SubscriptionRepository>() .AddSingleton <ITopologyProvider, TopologyProvider>() .AddTransient <IPublisherConfigurationFactory, PublisherConfigurationFactory>() .AddTransient <IBasicPublishConfigurationFactory, BasicPublishConfigurationFactory>() .AddTransient <IConsumerConfigurationFactory, ConsumerConfigurationFactory>() .AddTransient <IConsumeConfigurationFactory, ConsumeConfigurationFactory>() .AddTransient <IExchangeDeclarationFactory, ExchangeDeclarationFactory>() .AddTransient <IQueueConfigurationFactory, QueueDeclarationFactory>() .AddSingleton <INamingConventions, NamingConventions>() .AddSingleton <IExclusiveLock, ExclusiveLock>() .AddSingleton <IBusClient, BusClient>() .AddSingleton <IResourceDisposer, ResourceDisposer>() .AddTransient <IInstanceFactory>(resolver => new InstanceFactory(resolver)) .AddSingleton <IPipeContextFactory, PipeContextFactory>() .AddTransient <IExtendedPipeBuilder, PipeBuilder>(resolver => new PipeBuilder(resolver)) .AddSingleton <IPipeBuilderFactory>(provider => new PipeBuilderFactory(provider)); var clientBuilder = new ClientBuilder(); options?.Plugins?.Invoke(clientBuilder); clientBuilder.DependencyInjection?.Invoke(register); register.AddSingleton(clientBuilder.PipeBuilderAction); options?.DependencyInjection?.Invoke(register); return(register); }