Beispiel #1
0
        public static void Init()
        {
            var assembly = Assembly.GetExecutingAssembly();

            using var stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.appsettings.json");

            var iocSetup = new GuardedActionIoCSetup();

#pragma warning disable IDISP001 // Dispose created.
            var host = new HostBuilder()
                       .ConfigureHostConfiguration(c =>
            {
                c.AddCommandLine(new string[] { $"ContentRoot={FileSystem.AppDataDirectory}" });
                c.AddJsonStream(stream);
            })
                       .ConfigureLogging((l) => l.AddConsole(o =>
            {
                o.DisableColors = true;
            }))
                       .ConfigureServices(ConfigureServices)
                       .ConfigureGuardedActions(iocSetup, nameof(GuardedActionsPlayground))
                       .Build()
                       .ConnectGuardedActions(iocSetup);
#pragma warning restore IDISP001 // Dispose created.

            //Save our service provider so we can use it later.
            Services = host.Services;
        }
Beispiel #2
0
        public static IHost ConnectGuardedActions(this IHost host, GuardedActionIoCSetup ioCRegistration)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (ioCRegistration == null)
            {
                throw new ArgumentNullException(nameof(ioCRegistration));
            }

            ioCRegistration.SetServiceProvider(host.Services);

            return(host);
        }
Beispiel #3
0
        public static IHostBuilder ConfigureGuardedActions(this IHostBuilder builder, GuardedActionIoCSetup iocRegistration, params string[] assemblyNames)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (iocRegistration == null)
            {
                throw new ArgumentNullException(nameof(iocRegistration));
            }

            return(builder.ConfigureServices((_, sc) =>
            {
                iocRegistration.SetServiceCollection(sc);
                iocRegistration.Register(assemblyNames);
            }));
        }