1+ using System ;
2+ using Autofac ;
3+ using JetBrains . Annotations ;
4+ using Microsoft . Extensions . Configuration ;
5+ using Microsoft . Extensions . DependencyInjection ;
6+ using Rocket . Surgery . Conventions . Autofac ;
7+
8+ // ReSharper disable once CheckNamespace
9+ namespace Rocket . Surgery . Conventions
10+ {
11+ /// <summary>
12+ /// Class AutofacRocketHostExtensions.
13+ /// </summary>
14+ [ PublicAPI ]
15+ public static class AutofacConventionRocketHostExtensions
16+ {
17+ /// <summary>
18+ /// Uses the Autofac.
19+ /// </summary>
20+ /// <param name="builder">The builder.</param>
21+ /// <param name="delegate">The container.</param>
22+ /// <returns>IHostBuilder.</returns>
23+ public static ConventionContextBuilder ConfigureAutofac ( [ NotNull ] this ConventionContextBuilder builder , AutofacConvention @delegate )
24+ {
25+ if ( builder == null )
26+ {
27+ throw new ArgumentNullException ( nameof ( builder ) ) ;
28+ }
29+
30+ builder . AppendDelegate ( @delegate ) ;
31+ return builder ;
32+ }
33+
34+ /// <summary>
35+ /// Uses the Autofac.
36+ /// </summary>
37+ /// <param name="builder">The builder.</param>
38+ /// <param name="delegate">The container.</param>
39+ /// <returns>IHostBuilder.</returns>
40+ public static ConventionContextBuilder ConfigureAutofac (
41+ [ NotNull ] this ConventionContextBuilder builder ,
42+ Action < IConfiguration , IServiceCollection , ContainerBuilder > @delegate
43+ )
44+ {
45+ if ( builder == null )
46+ {
47+ throw new ArgumentNullException ( nameof ( builder ) ) ;
48+ }
49+
50+ builder . AppendDelegate ( new AutofacConvention ( ( context , configuration , services , container ) => @delegate ( configuration , services , container ) ) ) ;
51+ return builder ;
52+ }
53+
54+ /// <summary>
55+ /// Uses the Autofac.
56+ /// </summary>
57+ /// <param name="builder">The builder.</param>
58+ /// <param name="delegate">The container.</param>
59+ /// <returns>IHostBuilder.</returns>
60+ public static ConventionContextBuilder ConfigureAutofac ( [ NotNull ] this ConventionContextBuilder builder , Action < IServiceCollection , ContainerBuilder > @delegate )
61+ {
62+ if ( builder == null )
63+ {
64+ throw new ArgumentNullException ( nameof ( builder ) ) ;
65+ }
66+
67+ builder . AppendDelegate ( new AutofacConvention ( ( context , configuration , services , container ) => @delegate ( services , container ) ) ) ;
68+ return builder ;
69+ }
70+
71+ /// <summary>
72+ /// Uses the Autofac.
73+ /// </summary>
74+ /// <param name="builder">The builder.</param>
75+ /// <param name="delegate">The container.</param>
76+ /// <returns>IHostBuilder.</returns>
77+ public static ConventionContextBuilder ConfigureAutofac ( [ NotNull ] this ConventionContextBuilder builder , Action < ContainerBuilder > @delegate )
78+ {
79+ if ( builder == null )
80+ {
81+ throw new ArgumentNullException ( nameof ( builder ) ) ;
82+ }
83+
84+ builder . AppendDelegate ( new AutofacConvention ( ( context , configuration , services , container ) => @delegate ( container ) ) ) ;
85+ return builder ;
86+ }
87+ }
88+ }
0 commit comments