public static object ResolveDummyPopulation(IContainer container) { using (var scope = container.OpenScope()) { scope.Resolve <D1>(); scope.Resolve <D2>(); scope.Resolve <D3>(); scope.Resolve <D4>(); scope.Resolve <D5>(); scope.Resolve <D6>(); scope.Resolve <D7>(); scope.Resolve <D8>(); scope.Resolve <D9>(); scope.Resolve <D10>(); scope.Resolve <D11>(); scope.Resolve <D12>(); scope.Resolve <D13>(); scope.Resolve <D14>(); scope.Resolve <D15>(); scope.Resolve <D16>(); scope.Resolve <D17>(); scope.Resolve <D18>(); scope.Resolve <D19>(); return(scope.Resolve <D20>()); } }
public void SetUp() { _harmony = new DependencyContainer(); _harmony.Register(new Singleton()); _harmony.Resolve <Singleton>(); var builder = new ContainerBuilder(); builder.RegisterInstance(new Singleton()); _autofac = builder.Build(); _autofac.Resolve <Singleton>(); _ninject = new StandardKernel(); _ninject.Load(Assembly.GetExecutingAssembly()); _ninject.Bind <Singleton>().ToConstant(new Singleton()); _ninject.Get <Singleton>(); _dry = new Container(); _dry.Register <Singleton>(Reuse.Singleton); _dry.Resolve <Singleton>(); var services = new ServiceCollection(); services.AddSingleton(new Singleton()); _dotnet = services.BuildServiceProvider(); _dotnet.GetService <Singleton>(); _native = new Singleton(); }
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters private IContainer ConfigureContainer(IContainer container) { container.RegisterInstance(LoggerFactory); container.RegisterInstance(Logger); container.RegisterInstance(SerilogLogger); return(BuildContainer(container.WithDependencyInjectionAdapter())); }
public AppCore.IOC.IContainer ActiveWebApi(System.Web.Http.HttpConfiguration httpConfig, System.Reflection.Assembly[] webApiAssemblies) { _container = new DryContainer().WithWebApi(httpConfig, webApiAssemblies); _container.RegisterInstance <AppCore.IOC.IContainer>(new Container(_container), reuse: Reuse.Singleton); Container = _container.Resolve <AppCore.IOC.IContainer>(); return(Container); }
public ContainerHandlerFactory(DryIoc.IContainer container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } _container = container; }
public void Configure(DryIoc.IContainer container) { container.Resolve <ILoggerFactory>() .AddConsole(Configuration.GetSection("Logging")) .AddDebug(); ServicesExtensions.InitializeJobs(container); }
private static void RegisterRequiredServices(IContainer container) { container.Register <IActiveViewLocator, ActiveViewLocator>(Reuse.Singleton); container.Register <IScopedViewLocator, ScopedViewLocator>(Reuse.Scoped); container.Register <INavigationService, NavigationService>(Reuse.Scoped); container.Register <IViewConfiguration, DefaultViewConfigurations>(Reuse.Singleton, serviceKey: "defaultConfiguration"); container.Register <ILogger, NullLogger>(); }
private static void AutoRegisterViews(IContainer container) { var viewTypes = RegistrationSolver.GetViews(); foreach (var viewType in viewTypes) { container.RegisterForNavigation(viewType); } }
public void WarmUp() { _msDi = PrepareMsDi(); _dryioc = PrepareDryIoc(); _dryIocMsDi = PrepareDryIocMsDi(); _grace = PrepareGrace(); _graceMsDi = PrepareGraceMsDi(); _autofac = PrepareAutofac(); _autofacMsDi = PrepareAutofacMsDi(); }
public DryIocBenchmark() { _container = new DryIoc.Container(); foreach (var map in TransientMap) { _container.Register(map.Item1, map.Item2); } foreach (var map in SingletonMap) { _container.Register(map.Item1, map.Item2, Reuse.Singleton); } }
public IContainer Build() { var container = new DryIocContainerAdapter(); _dryContainer.RegisterInstance <IContainer>(container, IfAlreadyRegistered.Keep); _dryContainer = _dryContainer.WithNoMoreRegistrationAllowed(); // lock for new registrations container.Initialize(_dryContainer); _buildActions.Apply(action => action?.Invoke(container)); _buildActions.Clear(); return(container); }
/// <summary> /// Register the singleton ISession instance with the container once we can connect to the killrvideo schema. /// </summary> public async Task RegisterDseOnceAvailable(DryIoc.IContainer container) { IDseSession session = null; int attempts = 0; Logger.Information("Initializing connection to DSE Cluster..."); while (session == null) { try { Logger.Information("+ Reading node addresses from ETCD."); IEnumerable <string> hosts = await _serviceDiscovery .LookupServiceAsync(ConfigKeys.EtcdCassandraKey) .ConfigureAwait(false); // Create cluster builder with contact points var builder = DseCluster.Builder().AddContactPoints(hosts.Select(ToIpEndPoint)); // Authentication if (!string.IsNullOrEmpty(_kvConfig[ConfigKeys.DseUsername]) && !string.IsNullOrEmpty(_kvConfig[ConfigKeys.DsePassword])) { Logger.Information("+ Enable Authentication with user {user}", _kvConfig[ConfigKeys.DseUsername]); builder.WithAuthProvider( new DsePlainTextAuthProvider(_kvConfig[ConfigKeys.DseUsername], _kvConfig[ConfigKeys.DsePassword])); } else { Logger.Information("+ No Authentication"); } // SSL : To be tested (first try based on documentation) if (Boolean.Parse(_kvConfig[ConfigKeys.DseEnableSsl])) { String certPath = _kvConfig[ConfigKeys.DseSslCertPath]; String certPassword = _kvConfig[ConfigKeys.DseSslCertPassword]; if (string.IsNullOrEmpty(certPath)) { throw new ArgumentNullException("Cannot read SSL File " + certPath); } if (string.IsNullOrEmpty(certPath)) { throw new ArgumentNullException("Cannot read SSL Certificate password " + certPath); } Logger.Information("+ Setup SSL options with {certPath}", certPath); SSLOptions sslOptions = new SSLOptions(); X509Certificate2[] certs = new X509Certificate2[] { new X509Certificate2(ReadX509Certificate(certPath), certPassword) }; sslOptions.SetCertificateCollection(new X509CertificateCollection(certs)); sslOptions.SetRemoteCertValidationCallback((a1, a2, a3, a4) => true); //sslOptions.SetHostNameResolver((internalIPAddress) => { return "test_client"; }); builder.WithSSL(sslOptions); } else { Logger.Information("+ No SSL"); } // Query options var queryOptions = new QueryOptions(); queryOptions.SetConsistencyLevel(ConsistencyLevel.LocalQuorum); builder.WithQueryOptions(queryOptions); // Graph Options Logger.Information("+ Graph connection to {graphName}", _kvConfig[ConfigKeys.DseGraphName]); var graphOptions = new GraphOptions(); graphOptions.SetName(_kvConfig[ConfigKeys.DseGraphName]); graphOptions.SetReadTimeoutMillis(int.Parse(_kvConfig[ConfigKeys.DseGraphReadTimeout])); graphOptions.SetReadConsistencyLevel(ConsistencyLevel.One); graphOptions.SetWriteConsistencyLevel(ConsistencyLevel.One); builder.WithGraphOptions(graphOptions); // Cassandra session = builder.Build().Connect(_kvConfig[ConfigKeys.DseKeySpace]); Logger.Information("+ Session established to keyspace {keyspace}", _kvConfig[ConfigKeys.DseKeySpace]); } catch (Exception e) { attempts++; session = null; // Don't log exceptions until we've tried 6 times if (attempts >= int.Parse(_kvConfig[ConfigKeys.MaxRetry])) { Logger.Error(e, "Cannot connection to DSE after {max} attempts, exiting", _kvConfig[ConfigKeys.MaxRetry]); Environment.Exit(404); } } if (session != null) { continue; } Logger.Information("+ Attempt #{nb}/{max} failed.. trying in {delay} seconds, waiting Dse to Start", attempts, _kvConfig[ConfigKeys.MaxRetry], _kvConfig[ConfigKeys.RetryDelay]); await Task.Delay(int.Parse(_kvConfig[ConfigKeys.RetryDelay])).ConfigureAwait(false); } // Since session objects should be created once and then reused, register the instance with the container // which will register it as a singleton by default container.RegisterInstance(session); }
/// <summary> /// Initializes current service with the specified instance of <see cref="T:DryIoc.IContainer"/>. /// </summary> /// <param name="container">Instance of <see cref="T:DryIoc.IContainer"/>.</param> internal void Initialize(IDryContainer container) { _container = container ?? throw new ArgumentNullException(nameof(container)); }
public DryIocContainerBuilder() { _dryContainer = new Container(rules => rules.WithoutFastExpressionCompiler()); _buildActions = new List <Action <IContainer> >(); }
public static object Measure(IContainer container) { using (var scope = container.OpenScope()) return(scope.Resolve <R>()); }
public Container(IDryContainer container) { _container = container; }
public DryIocScope(DryIoc.IContainer scope) { _scope = scope; }
public static void Reset() { _container?.Dispose(); _container = null; }
public DryIocService(IContainer dryIocContainer) { dryIocContainer.With(rules => rules.WithTrackingDisposableTransients()); _dryIocContainer = dryIocContainer; _dryIocContainer.UseInstance <IIocService>(this, IfAlreadyRegistered.Throw); }