//public void Process(Type type, Registry registry) { // if (!type.IsConcrete()) { // return; // } // var interfaceTypes = type.FindInterfacesThatClose(typeof(IRepositoryWithTypedId<,>)); // foreach (var closedGenericType in interfaceTypes) { // if (GenericsPluginGraph.CanBeCast(closedGenericType, type)) { // registry.For(closedGenericType).Singleton().Use(type).Named(type.Name); // } // } //} public void ScanTypes(TypeSet types, Registry registry) { var t = types.FindTypes(TypeClassification.Concretes); if (!t.Any()) { return; } //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)); //}); var interfaceTypes = types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).All(type => { // Register against all the interfaces implemented // by this concrete class type.GetInterfaces().All(@interface => { registry.For(@interface).Use(type); return(true); }); return(true); }); }
public void ScanTypes(TypeSet types, ServiceRegistry services) { var interfaces = types.FindTypes(TypeClassification.Interfaces | TypeClassification.Closed).Where(x => x != typeof(IDisposable)); var concretes = types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).Where(x => x.GetConstructors().Any()).ToArray(); interfaces.Each(@interface => { var implementors = concretes.Where(x => x.CanBeCastTo(@interface)).ToArray(); if (implementors.Count() == 1) { services.AddType(@interface, implementors.Single()); } }); }
public void ScanTypes(TypeSet types, IServiceCollection services) { var interfaces = types.FindTypes(TypeClassification.Interfaces); var concretes = types.FindTypes(TypeClassification.Concretes).Where(x => TypeExtensions.HasConstructors(x)).ToArray(); interfaces.Each(@interface => { var implementors = concretes.Where(x => x.CanBeCastTo(@interface)).ToArray(); if (implementors.Count() == 1) { services.AddType(@interface, implementors.Single()); } }); }
public override void ScanTypes(TypeSet types, Registry registry) { var interfaces = types.FindTypes(TypeClassification.Interfaces); var concretes = types.FindTypes(TypeClassification.Concretes).Where(x => x.HasConstructors()).ToArray(); interfaces.Each(@interface => { var implementors = concretes.Where(x => x.CanBeCastTo(@interface)).ToArray(); if (implementors.Count() == 1) { registry.AddType(@interface, implementors.Single()); ConfigureFamily(registry.For(@interface)); } }); }
public void ScanTypes(TypeSet types, IServiceCollection services) { types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).Where(Matches).Each(type => { services.AddType(determineLeastSpecificButValidType(_pluginType, type), type); }); }
public void ScanTypes(TypeSet types, Registry registry) { //// https://stackoverflow.com/questions/49702579/structuremap-interception-of-controllers //// Attach a policy to intercept all Controllers before attaching Controllers...but it raises error. //// "Decorator Interceptor failed during object construction. Specified type is not an interface,Parameter name: interfaceToProxy" //registry.Policies.Interceptors( // new DynamicProxyInterceptorPolicy( // x => (x.IsConcrete() | !x.IsOpenGeneric()) & (x.CanBeCastTo<Controller>() | x.CanBeCastTo<ApiController>()), // new IInterceptionBehavior[] // { // new AuthorisationInterceptor(), // //new AuditingInterceptor() // } // )); // Now find all Controllers/ApiControllers: var foundControllers = types.FindTypes( TypeClassification.Concretes | TypeClassification.Closed) .Where(x => x.CanBeCastTo <Controller>() | x.CanBeCastTo <ApiController>()) .ToArray(); // to register them with StructureMap as themselves (ie, no 'Use' statement): foreach (var serviceType in foundControllers) { registry.For(serviceType).LifecycleIs(new UniquePerRequestLifecycle()); // Although when I tried use/fore, it also raised {"Specified type is not an interface\r\nParameter name: interfaceToProxy"} // AttachBehaviour(registry, serviceType); } //registry.For<IController>().InterceptWith(new DynamicProxyInterceptor<IController>(new IInterceptionBehavior[]{new AuthorisationInterceptor()})); }
public void ScanTypes(TypeSet types, ServiceRegistry services) { var publisherComponentTypes = types .FindTypes(TypeClassification.Concretes | TypeClassification.Closed) .Where(t => t.GetInterfaces().Contains(typeof(PublisherComponent))); // Register publisher components foreach (var type in publisherComponentTypes) { var resultProviderInterface = type.GetInterfaces().SingleOrDefault(IsResultProviderInterface); if (resultProviderInterface == default) { // Not yet registered services.AddScoped(typeof(PublisherComponent), type); } else { // Already registered as ResultProvider, forward the invocation services .For <PublisherComponent>() .Use(scope => (PublisherComponent)scope.GetService(resultProviderInterface)) .Named(type.NameInCode()); } } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).Where(t => t.CanBeCastTo <Controller>())) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } }
public void ScanTypes(TypeSet types, Registry registry) { types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).ForEach(type => { registry.For(type.GetTypeInfo().BaseType).Use(type).ContainerScoped(); }); }
public void ScanTypes(TypeSet types, Registry registry) { var configuredMarkerType = typeof(IConfigured); var configuredTypes = types .FindTypes(TypeClassification.Concretes) .Where(t => configuredMarkerType.IsAssignableFrom(t)); foreach (var type in configuredTypes) { registry .For(type) .Use("Reactive.Config", ctx => { var provider = ctx.GetInstance <IConfigurationProvider>(); var method = provider.GetType().GetMethod("Get"); if (method == null) { throw new NotImplementedException("IConfigurationProvider has to have a GET method. It is in the interface!"); } var generic = method.MakeGenericMethod(type); return(generic.Invoke(provider, null)); }); } }
public void ScanTypes(TypeSet types, Registry registry) { types.FindTypes(TypeClassification.Concretes).Where(Matches).Each(type => { var name = _getName(type); registry.AddType(GetLeastSpecificButValidType(_pluginType, type), type, name); }); }
public void ScanTypes(TypeSet types, Registry registry) { types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).ToList().ForEach(type => { // Register against all the interfaces implemented // by this concrete class type.GetInterfaces().ToList().ForEach(@interface => registry.For(@interface).Use(type)); }); }
public void ScanTypes(TypeSet types, Registry registry) { var matches = types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed) .Where(type => type.CanBeCastTo <ITeam>()); foreach (var type in matches) { registry.For(typeof(ITeam)).Add(type); } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed) .Where(type => typeof(TPluginFamily).IsAssignableFrom(type))) { registry.ForSingletonOf(type); registry.For(typeof(TPluginFamily)).Use(c => c.GetInstance(type)); //registry.For(type).Use(c => c.GetInstance(type)); } }
public void ScanTypes(TypeSet types, ServiceRegistry services) { foreach (var type in types.FindTypes(TypeClassification.Concretes).Where(type => type.Name.EndsWith("ViewModel") && type.GetConstructors().Any())) { if (type != null && ShouldAdd(services, type, type)) { services.AddTransient(type, type); } } }
public void ScanTypes(TypeSet types, ServiceRegistry registry) { types.FindTypes(TypeClassification.Closed | TypeClassification.Concretes) .Where(IsPublicRegistry) .Each(type => { var found = Activator.CreateInstance(type).As <ServiceRegistry>(); registry.IncludeRegistry(found); }); }
public void ScanTypes(TypeSet types, Registry services) { foreach (var type in types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed)) { foreach (var @interface in type.GetInterfaces()) { services.For(@interface).Use(type); } } }
public void ScanTypes(TypeSet types, Registry registry) { foreach(Type type in types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed) { foreach(Type interfaceType in type.GetInterfaces()) { registry.For(interfaceType).Use(type); } } }
public void ScanTypes(TypeSet types, Registry registry) { types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).ForEach(type => { if (type.CanBeCastTo <T>()) { registry.For(typeof(T)).LifecycleIs(new UniquePerRequestLifecycle()).Add(type); } }); }
public override void ScanTypes(TypeSet types, Registry registry) { var typeCollection = types.FindTypes(TypeClassification.Concretes) .Where(type => type.IsConcreteAndAssignableTo(typeof(IRecurringBackgroundJob))); foreach (var t in typeCollection) { RecurringJobTypes.Add(t); } }
public void ScanTypes(TypeSet types, Registry registry) { foreach (var type in types.FindTypes(TypeClassification.All)) { if (type.CanBeCastTo <ApiController>() && !type.IsAbstract) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } } }
public void ScanTypes(TypeSet types, ServiceRegistry services) { var forwardingTypes = types.FindTypes(TypeClassification.Closed) .Where(t => TypeExtensions.Closes(t, typeof(IForwardsTo <>))); foreach (var type in forwardingTypes) { _forwarders.Add(type); } }
public void ScanTypes(TypeSet types, ServiceRegistry services) { foreach (var type in types.FindTypes(TypeClassification.Concretes).Where(type => type.GetConstructors().Any())) { var serviceType = FindPluginType(type); if (serviceType != null && ShouldAdd(services, serviceType, type)) { services.AddScoped(serviceType, type); } } }
public void ScanTypes(TypeSet types, IServiceCollection services) { foreach (var type in types.FindTypes(TypeClassification.Concretes).Where(x => x.HasConstructors())) { var interfaceType = type.AllInterfaces().FirstOrDefault(); if (interfaceType != null) { services.AddType(interfaceType, type); } } }
public void ScanTypes(TypeSet types, IServiceCollection services) { foreach (var type in types.FindTypes(TypeClassification.Concretes).Where(x => x.GetConstructors().Any())) { var interfaceType = type.GetInterfaces().FirstOrDefault(x => x != typeof(IDisposable)); if (interfaceType != null && !interfaceType.HasAttribute <LamarIgnoreAttribute>() && !type.IsOpenGeneric()) { services.AddType(interfaceType, type); } } }
public void ScanTypes(TypeSet types, Registry registry) { // Only work on concrete types types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).ForEach(type => { if (type.Name.EndsWith("Job")) { registry.For(type).Singleton(); } }); }
/// <summary> /// Adds SagaStateMachines to the registry, using the factory method, and updates the registrar prior to registering so that the default /// saga registrar isn't notified. /// </summary> /// <param name="configurator"></param> /// <param name="registrar"></param> /// <param name="assemblies">The assemblies to scan for state machines</param> public static void AddSagaStateMachines(this IRegistrationConfigurator configurator, ISagaStateMachineRegistrar registrar, params Assembly[] assemblies) { if (assemblies.Length == 0) { assemblies = AppDomain.CurrentDomain.GetAssemblies(); } TypeSet types = AssemblyTypeCache.FindTypes(assemblies, IsSagaStateMachineOrDefinition).GetAwaiter().GetResult(); configurator.AddSagaStateMachines(registrar, types.FindTypes(TypeClassification.Concrete).ToArray()); }
public static void RegisterSagaStateMachines(this ISagaStateMachineRegistrar registrar, params Assembly[] assemblies) { if (assemblies.Length == 0) { assemblies = AppDomain.CurrentDomain.GetAssemblies(); } TypeSet types = AssemblyTypeCache.FindTypes(assemblies, x => x.HasInterface(typeof(SagaStateMachine <>))).GetAwaiter().GetResult(); registrar.RegisterSagaStateMachines(types.FindTypes(TypeClassification.Concrete).ToArray()); }
public void ScanTypes(TypeSet types, Registry registry) { // Only work on concrete types types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).Each(type => { if (type.CanBeCastTo <Controller>() && !type.IsAbstract) { registry.For(type).LifecycleIs(new UniquePerRequestLifecycle()); } }); }
public void ScanTypes(TypeSet types, IServiceCollection services) { foreach (var type in types.FindTypes(TypeClassification.Concretes).Where(type => type.HasConstructors())) { var pluginType = FindPluginType(type); if (pluginType != null) { services.AddType(pluginType, type); } } }