コード例 #1
0
ファイル: Program.cs プロジェクト: jnpatel340/CroweHorwath
        public static void Main(string[] args)
        {
            if (Enum.IsDefined(typeof(OutputDeviceType), AppSettings.Settings.OutputDevice))
            {
                OutputDeviceType type;
                Enum.TryParse <OutputDeviceType>(AppSettings.Settings.OutputDevice, out type);

                Writer writer = WriterFactory.Create(type);

                IHelloWriter hwriter = IHelloWorldWriterFactory.Create(writer);
                hwriter.Write();
            }
            else
            {
                throw new ApplicationException(string.Format("Unable to Output to {0}.", AppSettings.Settings.OutputDevice));
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kingmotley/HelloWorldApi
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IWriter>(w =>
            {
                var config = new ConfigurationBuilder()
                             .AddJsonFile("appsettings.json", true, true)
                             .Build();

                var factory = new WriterFactory();
                return(factory.GetWriter(config["writer"]));
            })
                                  .AddSingleton <IApi, Api>()
                                  .BuildServiceProvider();

            var api = serviceProvider.GetService <IApi>();

            api.Write();
        }