private static ContainerBuilder GetContainerBuilder()
        {
            var configurationBuilderFactory = new ConfigurationBuilderFactory();
            var configurationBuilder        = configurationBuilderFactory.GetBuilder();

            var containerFactory = new ContainerBuilderFactory();
            var builder          = containerFactory.GetBuilder(configurationBuilder.Build());

            return(builder);
        }
        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();
        }
Exemplo n.º 3
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();
Exemplo n.º 4
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)
            {
            }
        }
        public static IContainer BuildApplicationContainer(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddAutofac();

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Generating {Class}", nameof(ContainerBuilder));
            IContainerBuilderFactory builderFactory = new ContainerBuilderFactory();
            var builder = builderFactory.GetBuilder(configuration);

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Registering layer types to {Class}", nameof(ContainerBuilder));
            builder.RegisterLayerTypes(configuration);

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Registering UI Instances to {Class}", nameof(ContainerBuilder));
            builder.RegisterInstance(configuration);

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Populating services in {Class}", nameof(ContainerBuilder));
            builder.Populate(services);

            return(builder.Build());
        }
Exemplo n.º 6
0
        protected void ConfigureApplicationContainer(IServiceCollection services)
        {
            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Generating {Class}", nameof(ContainerBuilder));
            IContainerBuilderFactory builderFactory = new ContainerBuilderFactory();
            var builder = builderFactory.GetBuilder(Configuration);

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Registering layer types to {Class}", nameof(ContainerBuilder));
            IContainerBuilderLayerFactory builderRegistry = new ContainerBuilderLayerFactory();

            builderRegistry.RegisterBuilderLayerTypes(ref builder);

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Registering UI Instances to {Class}", nameof(ContainerBuilder));
            builder.RegisterInstance(Configuration);

            Log.Logger.LogEventVerbose(LoggerEvents.STARTUP, "Populating services in {Class}", nameof(ContainerBuilder));
            builder.Populate(services);

            ApplicationContainer = builder.Build();
        }
        public void DefaultIsEmpty()
        {
            var factory = new ContainerBuilderFactory();

            //var fac = new FacContainerBuilder();

            factory.ContainerBuilder.RegisterType <ConsoleLogger, ILogger>();

            factory.ContainerBuilder.RegisterAssemblyTypes(k => k.Name.EndsWith("Repository") || k.Name.EndsWith("Record"));

            var repository = factory.ContainerBuilder.Resolve <ITestRepository>();

            var record = factory.ContainerBuilder.Resolve <ITestRecord>();

            Console.WriteLine(repository.Write());
            Console.WriteLine(record.write());

            ILogger log = factory.ContainerBuilder.Resolve <ILogger>();

            factory.ContainerBuilder.Dispose();

            var str = log.writer();
        }