Esempio n. 1
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .UseServiceProviderFactory(new AutofacServiceProviderFactory())
        .ConfigureContainer <ContainerBuilder>(builder =>
        {
            ContainerBuilderFactory.RegisterTypes(builder);

            builder.RegisterType <NLogLoggerFactory>().AsImplementedInterfaces().InstancePerLifetimeScope();
        })
        .ConfigureServices((hostContext, services) =>
        {
            services.AddHostedService <Worker>();
        })
        .UseWindowsService();
        public static void RegisterServices()
        {
            var builder = new ContainerBuilder();

            ContainerBuilderFactory.RegisterTypes(builder);

            builder.RegisterType <NLogLoggerFactory>().AsImplementedInterfaces().InstancePerLifetimeScope();
            builder.RegisterType <Messenger>().As <IMessenger>().SingleInstance();

            builder.RegisterType <MainViewModel>().AsSelf().SingleInstance();
            builder.RegisterType <AboutViewModel>().AsSelf().SingleInstance();

            container = builder.Build();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            ContainerBuilderFactory.RegisterTypes(builder);
            builder.RegisterType <NLogLoggerFactory>().AsImplementedInterfaces().InstancePerLifetimeScope();
            var container = builder.Build();

            var service = container.Resolve <IExportService>();

            service.Start();
            while (true)
            {
            }
        }