protected override void Action(IConventionalContext context) { _types.FindAll(context.GetTypePredicate().Compile()).ForEach( t => context.Get <ICollection <IRegisterAssemblyServiceSelector> >("Service").ForEach( selector => selector.Select(t).ForEach( s => context.Services.ReplaceOrAdd(ServiceDescriptor.Describe(s, t, context.GetOrAdd <IRegisterAssemblyLifetimeSelector>("Lifetime", new LifetimeSelector(ServiceLifetime.Transient)).Select(t)))))); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="name"></param> /// <param name="factory"></param> /// <returns></returns> public static T GetOrDefault <T>(this IConventionalContext context, string name, Func <string, T> factory) { var result = (context as ConventionalContext).GetItem <T>(name); if (Equals(result, default(T))) { result = factory(name); } return(result); }
} /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> public static T GetOrAdd <T>(this IConventionalContext context, string name, T value) { var result = (context as ConventionalContext).GetItem <T>(name); if (Equals(result, default(T))) { context.Set(name, value); result = value; } return(result); }
protected override void Action(IConventionalContext context) { context.Types.ForEach( t => context.Get <ICollection <IRegisterAssemblyServiceSelector> >("Service").ForEach( selector => selector.Select(t).ForEach( s => context.Services.ReplaceOrAdd( ServiceDescriptor.Describe(s, t, context.GetOrAdd <IRegisterAssemblyLifetimeSelector>("Lifetime", new LifetimeSelector(ServiceLifetime.Transient)).Select(t)), t.GetAttribute <ReplaceServiceAttribute>()?.ReplaceService ?? false )))); }
/// <summary> /// /// </summary> /// <param name="context"></param> protected override void Action(IConventionalContext context) { var action = context.Services.GetSingletonInstanceOrNull <IProxyConventionalAction>(); if (action == null) { return; } var typeList = context.GetOrDefault(Interceptors, default(ITypeList <IInterceptor>)); var ctx = new ProxyConventionalActionContext(context.Services, context.Types.Where(t => t.IsStandardType()), context.TypePredicate, typeList); action.Action(ctx); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext AsDefault(this IConventionalContext context) { context.As(new DefaultInterfaceSelector()); return context; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext AsExposeService(this IConventionalContext context) { context.As(new ExposeServicesSelector()).Lifetime(new ExposeLifetimeSelector()); return context; }
/// <summary> /// /// </summary> /// <param name="context"></param> protected abstract void Action(IConventionalContext context);
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext As<T>(this IConventionalContext context) { context.As(new TypeSelector<T>()); return context; }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="name"></param> /// <returns></returns> public static T Get <T>(this IConventionalContext context, string name) { return((context as ConventionalContext).GetItem <T>(name)); } /// <summary>
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="predicate"></param> /// <returns></returns> public static IConventionalContext Where(this IConventionalContext context, Predicate <Type> predicate) { (context as ConventionalContext).AddPredicate(predicate); return(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext AutoActivation(this IConventionalContext context) { context.Set("HandlerActivationTypeSelector", new ExposeActivationTypeSelector()); return(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="lifetimeSelector"></param> /// <returns></returns> public static IConventionalContext Lifetime(this IConventionalContext context, IRegisterAssemblyLifetimeSelector lifetimeSelector) { context.Set("Lifetime", lifetimeSelector); return context; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext <ConventionalDependencyAction> AsAll(this IConventionalContext <ConventionalDependencyAction> context) { context.As(AllInterfaceSelector.Instance); return(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="activationType"></param> /// <returns></returns> public static IConventionalContext ActivationByType(this IConventionalContext context, EventHandlerActivationType activationType) { context.Set("HandlerActivationTypeSelector", new ActivationTypeSelector(activationType)); return(context); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> public static T GetOrDefault <T>(this IConventionalContext context, string name, T value) => GetOrDefault <T>(context, name, key => value);
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="name"></param> /// <returns></returns> public static T Get <T>(this IConventionalContext context, string name) => (context as ConventionalContext).GetItem <T>(name);
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext <ConventionalDependencyAction> AsSelf(this IConventionalContext <ConventionalDependencyAction> context) { context.As(SelfSelector.Instance); return(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext AsSelf(this IConventionalContext context) { context.As(new SelfSelector()); return context; }
protected override void Action(IConventionalContext context) { var types = context.Types.ToArray(); context.Services.PreConfigure <BackgroundJobOptions>(opts => types.ForEach(t => opts.AddJob(t))); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="serviceLifetime"></param> /// <returns></returns> public static IConventionalContext Lifetime(this IConventionalContext context, ServiceLifetime serviceLifetime) { context.Set("Lifetime", new LifetimeSelector(serviceLifetime)); return context; }
/// <summary> /// /// </summary> /// <param name="context"></param> protected override void Action(IConventionalContext context) { context.Types.ForEach( t => context.Services.Configure <EventBusOptions>(options => options.Handlers.Add(EventHandlerDescriptor.Describe(t, context.Get <IEventHandlerActivationTypeSelector>("HandlerActivationTypeSelector").Select(t))))); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="name"></param> /// <param name="value"></param> public static void Set(this IConventionalContext context, string name, object value) { (context as ConventionalContext).SetItem(name, value); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="serviceSelector"></param> /// <returns></returns> public static IConventionalContext <ConventionalDependencyAction> As(this IConventionalContext <ConventionalDependencyAction> context, IRegisterAssemblyServiceSelector serviceSelector) { context.GetOrAdd <ICollection <IRegisterAssemblyServiceSelector> >("Service", new HashSet <IRegisterAssemblyServiceSelector>()).Add(serviceSelector); return(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext <ConventionalDependencyAction> As <T>(this IConventionalContext <ConventionalDependencyAction> context) { context.As(new TypeSelector <T>()); return(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="serviceSelector"></param> /// <returns></returns> public static IConventionalContext As(this IConventionalContext context, IRegisterAssemblyServiceSelector serviceSelector) { context.GetOrAdd<ICollection< IRegisterAssemblyServiceSelector>>("Service",new HashSet<IRegisterAssemblyServiceSelector>()).Add(serviceSelector); return context; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static Expression <Predicate <Type> > GetTypePredicate(this IConventionalContext context) { return((context as ConventionalContext).TypePredicate); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public static IConventionalContext <ConventionalDependencyAction> AsExposeService(this IConventionalContext <ConventionalDependencyAction> context) { context.As(ExposeServicesSelector.Instance).Lifetime(ExposeLifetimeSelector.Instance); return(context); }
protected override void Action(IConventionalContext context) => context.Types.ForEach(t => context.Services.Configure <InitializationOptions>(opts => opts.AddInitializable(t, InitializationOrderAttribute.GetOrder(t))));
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="lifetimeSelector"></param> /// <returns></returns> public static IConventionalContext <ConventionalDependencyAction> Lifetime(this IConventionalContext <ConventionalDependencyAction> context, IRegisterAssemblyLifetimeSelector lifetimeSelector) { context.Set("Lifetime", lifetimeSelector); return(context); }