public void ScanTypes(TypeSet types, Registry registry) //ja tas ir kontolieris un nav abstracts, tad tas ir unique per request { foreach (var type in types.AllTypes()) { Process(type, registry); } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes().Where(type => type.CanBeCastTo <Controller>() && !type.IsAbstract)) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } }
public void ScanTypes(TypeSet types, Registry registry) { /* * The strategy here is to look for all types which inherit from Control * (which includes Page and MasterPage), are not abstract, and have at * least one constructor parameter. When that's the case then we register * the type for itself and ensure we get a new instance everytime. */ foreach (var type in types.AllTypes()) { if (typeof(Control).IsAssignableFrom(type) && !type.IsAbstract) { var ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance); foreach (var ctor in ctors) { if (ctor.GetParameters().Any()) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } } } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { registry.For(type).Singleton(); } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } }
public void ScanTypes(TypeSet types, ServiceRegistry services) { var commandExecutorTypes = types .AllTypes() .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Any(z => SupportedCommandExecutors.Contains(z.Name))) .Select(x => new { Type = x, Interface = x.GetInterfaces().SingleOrDefault(z => SupportedCommandExecutors.Contains(z.Name)) }) .Select(x => new { x.Type, x.Interface, Command = x.Interface.GenericTypeArguments.FirstOrDefault() }) .ToList(); if (commandExecutorTypes.Count == 0) { return; } foreach (var commandExecutorType in commandExecutorTypes) { var instance = services .For(commandExecutorType.Interface) .Use(commandExecutorType.Type) .Named(commandExecutorType.Command?.Name) .Scoped(); instance.Lifetime = this.serviceLifetime; } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { Process(type, registry); } }
public void ScanTypes(TypeSet types, Registry registry) { registry.Scan(scanner => { var allTypes = types.AllTypes(); scanner.Include(x => allTypes.Contains(x)); }); }
public void ScanTypes(TypeSet types, Registry registry) { types.AllTypes().ToList().ForEach(type => { if (type.CanBeCastTo <Controller>() && !type.IsAbstract) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } }); }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (type.CanBeCreated()) { registry.For(typeof(TPluginFamily)).Singleton().Use(type); } } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (Type type in types.AllTypes()) { if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } }
public void ScanTypes(TypeSet types, Registry registry) { types.AllTypes().ForEach(type => { if (FilterTypes(type)) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } }); }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes().Where(x => x.CanBeCastTo(typeof(Controller)) && !x.IsInterfaceOrAbstract())) { if (type.CanBeCastTo(typeof(Controller)) && !type.IsInterfaceOrAbstract()) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (!type.IsConcrete() || !type.CanBeCreated() || !type.AllInterfaces().Contains(typeof(T))) { continue; } registry.For(typeof(T)).Singleton().Use(type); } }
#pragma warning disable 1591 public void ScanTypes(TypeSet types, Registry registry) #pragma warning restore 1591 { foreach (var type in types.AllTypes()) { if (type.CanBeCastTo <Controller>() && !type.IsAbstract) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } }
public void ScanTypes(TypeSet types, Registry registry) { var typeList = types.AllTypes(); foreach (var type in typeList) { if (type.CanBeCastTo <ControllerConvention>() && !type.IsAbstract) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (type.CanBeCastTo <Controller>() && !type.IsAbstract) { //MVC: System.Web.Mvc.ControllerBase.VerifyExecuteCalledOnce() //A single instance of controller 'XxxController' cannot be used to handle multiple requests. //If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request. registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } }
static IList <Type> FindTypes <T>(IKernel kernel, Func <Type, bool> filter) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); TypeSet types = AssemblyTypeCache.FindTypes(assemblies, typeof(T).IsAssignableFrom).Result; return(types.AllTypes() .SelectMany(kernel.GetBindings) .Select(x => x.Service) .Distinct() .Where(filter) .ToList()); }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes().Where(type => type.CanBeCastTo <Controller>() && !type.IsAbstract)) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } //types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).Each(type => //{ // // Register against all the interfaces implemented // // by this concrete class // type.GetInterfaces().Each(@interface => registry.For(@interface).Use(type)); //}); }
public override void ScanTypes(TypeSet types, Registry registry) { types.AllTypes().Each(type => { IEnumerable <Type> interfaceTypes = type.FindInterfacesThatClose(_openType); if (!interfaceTypes.Any()) { return; } if (type.IsConcrete()) { _concretions.Add(type); } foreach (Type interfaceType in interfaceTypes) { _interfaces.Fill(interfaceType); } }); _interfaces.Each(@interface => { var expression = registry.For(@interface); ConfigureFamily(expression); var exactMatches = _concretions.Where(x => x.CanBeCastTo(@interface)).ToArray(); if (exactMatches.Length == 1) { expression.Use(exactMatches.Single()); } else { exactMatches.Each(type => expression.Add(type)); } if ([email protected]()) { addConcretionsThatCouldBeClosed(@interface, expression); } }); _concretions.Each(type => registry.Configure(graph => graph.ConnectedConcretions.Fill(type))); }
public void ScanTypes(TypeSet types, Registry registry) { List <LanguagePopupMessage> dec = new List <LanguagePopupMessage>(); foreach (Type type in types.AllTypes()) { if (!Attribute.IsDefined(type, typeof(ContainsTranslationDefinition))) { continue; } _FindConfigDeclarations(type, dec); } foreach (LanguagePopupMessage languagePopupMessage in dec) { Console.WriteLine($"{languagePopupMessage}"); } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (!type.IsConcrete() || !type.CanBeCreated() || !type.AllInterfaces().Contains(typeof(TPluginFamily))) { continue; } if (type == typeof(AboutViewModel)) // Just a sample. Remove this check, if you want all of your ViewModels become Singleton. { // How to mark a view model as Singleton registry.For(typeof(TPluginFamily)).Singleton().Use(type).Named(type.Name); } } }
/// <inheritdoc /> public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (type == pluginType || !type.CanBeCastTo(pluginType)) { continue; } if (!type.HasConstructors()) { throw new InvalidProgramException( string.Format("The profile of type: {0} has no accessible constructor!", type)); } registry.AddType(GetLeastSpecificButValidType(pluginType, type), type); } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (type.IsAbstract) { return; } var interfaceName = this.GetInterfaceName(type); var interfaceType = type.GetInterface(interfaceName); if (interfaceType != null) { registry.AddType(interfaceType, type); } } }
public void ScanTypes( TypeSet types, ServiceRegistry services) { foreach (var type in types.AllTypes()) { var interfaceTypes = type.FindInterfacesThatClose(_openType).ToArray(); if (!interfaceTypes.Any()) { continue; } if (type.IsConcrete()) { _concretions.Add(type); } foreach (var interfaceType in interfaceTypes) { _interfaces.Fill(interfaceType); } } foreach (var @interface in _interfaces) { var exactMatches = _concretions.Where(x => x.CanBeCastTo(@interface)).ToArray(); foreach (var type in exactMatches) { services.Add(new ServiceDescriptor(@interface, type, _lifetime)); } if ([email protected]()) { addConcretionsThatCouldBeClosed(@interface, services); } } var concretions = services.ConnectedConcretions(); foreach (var type in _concretions) { concretions.Fill(type); } }
public void ScanTypes(TypeSet types, ServiceRegistry services) { var concreteValidators = types .AllTypes() .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces() .Select(z => z.Name) .Intersect(SupportedValidators) .Any()); foreach (var concreteValidator in concreteValidators) { var validInterfaces = concreteValidator .GetInterfaces() .Where(x => SupportedValidators.Contains(x.Name)); foreach (var validInterface in validInterfaces) { var instance = services.For(validInterface).Use(concreteValidator); instance.Lifetime = serviceLifetime; } } }
// for StructureMap: public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { if (!type.Name.EndsWith("View") || !type.IsConcrete()) { return; } registry.For(typeof(object)).Use(type).Named(type.Name); } /* * // only interested in non abstract concrete types that have a matching named interface and start with Sql * if (type.IsAbstract || !type.IsClass || type.GetInterface(type.Name.Replace("Sql", "I")) == null) * return; * * // Get interface and register (can use AddType overload method to create named types * Type interfaceType = type.GetInterface(type.Name.Replace("Sql", "I")); * registry.AddType(interfaceType, type); */ }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.AllTypes()) { var contract = type.GetInterface($"I{type.Name}"); var diAttribute = type.GetCustomAttribute <DIAttribute>(); var cantBeInjected = contract == null || diAttribute == null || type.IsAbstract || !type.IsClass; if (cantBeInjected) { continue; } registry .For(contract) .Add(type) .SetLifecycleTo(GetLifeCycleByDIAttribute(diAttribute)); } }