Example #1
0
        static App()
        {
            var builder = new ContainerBuilder();

            AutofacRegistrator.RegisterTypes(builder);
            Container = builder.Build();
        }
Example #2
0
        static void Main(string[] args)
        {
            string route = "listener2";

            if (args.Any())
            {
                route = args[0];
            }

            var autofacRegistrator = new AutofacRegistrator();
            var configurator       = new QueueConfigurator(autofacRegistrator, new MessagingDependencyRegistrator())
                                     .RegisterHandler <DefaultHandler>()
                                     .RegisterHandler <AnotherDefaultHandler>();

            var builder    = configurator.Build(autofacRegistrator.CreateResolver());
            var subscriber = builder.GetSubscriber();

            subscriber.Subscribe <DefaultHandler, DomainMessage>();
            subscriber.Subscribe <AnotherDefaultHandler, AnotherDomainMessage>();

            var mongoMessageListener = builder.GetListener();

            mongoMessageListener.Start(route, CancellationToken.None).Wait();
            Console.WriteLine($"started listener {route}");
            Console.ReadLine();
        }
Example #3
0
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            AutofacRegistrator.RegisterComponents(containerRegistry);
            containerRegistry.RegisterForNavigation <NavigationPage>();

            containerRegistry.RegisterForNavigation <DocumentsListPage, DocumentsListPageViewModel>();
            containerRegistry.RegisterForNavigation <DocumentOrderPage, DocumentOrderPageViewModel>();
            containerRegistry.RegisterForNavigation <SendMessagePage, SendMessagePageViewModel>();
        }
        public void Setup()
        {
            var autofacRegistrator = new AutofacRegistrator();
            var configurator       = new QueueConfigurator(autofacRegistrator, GetRegistrtor());

            configurator
            .SetConfigurationProvider(TestMessagingConfiguration.Create())
            .SetTopicProvider <TestTopicNameProvider>()
            .RegisterHandler <TestHandler>()
            .RegisterHandler <SlightlyDifferentTestHandler>()
            .RegisterHandler <ResendHandler>()
            .RegisterHandler <TimeConsumingHandler>();
            Resolver = autofacRegistrator.CreateResolver();
            Builder  = configurator.Build(Resolver);
            ClearDb();
        }
        protected IContainer ConfigIoc(HttpConfiguration config)
        {
            // Get Autofac builder
            var builder = new ContainerBuilder();

            // Register your Web API controllers.
            builder.RegisterApiControllers(Assemblies);

            // OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(config);


            builder.RegisterType <MemoryCacheProvider>().As <ICacheProvider>().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies).SingleInstance();

            var registrator = new AutofacRegistrator(builder);

            // Set dependencies for Common services
            //registrator.RegisterType<MemoryCacheProvider, ICacheProvider>(DependencyScope.Singletone);
            //registrator.RegisterInstance<ICacheProvider>(new MemoryCacheProvider());
            registrator.RegisterType <AppSettingsProvider, ISettingsProvider>();
            registrator.RegisterType <ApiSubscriberProvider, ISubscriber>();
            registrator.RegisterType <ApiSubscriberProvider, ITokenProvider>();
            registrator.RegisterType <FamilyInfrastructureProvider, IFamilyInfrastructureProvider>();

            // Set dependencies for Extra services
            registrator.RegisterType <AuthenticationService, IAuthenticationProvider>();
            registrator.RegisterType <ThumbnailProvider, IThumbnailProvider>();

            // Register Modules
            (new FamilyApiConfiguration()).Config(registrator);

            // build Container
            var container = registrator.Build();

            // resolve dependencies in WebAPI
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            // resolve dependencies in Domain Events
            DomainEvents.Container = new AutofacResolver(container);

            return(container);
        }
Example #6
0
        static async Task DoStuff()
        {
            var autofacRegistrator = new AutofacRegistrator();
            var configurator       = new QueueConfigurator(autofacRegistrator, new MessagingDependencyRegistrator());

            var builder   = configurator.Build(autofacRegistrator.CreateResolver());
            var publisher = builder.GetPublisher();

            while (true)
            {
                try
                {
                    var rnd  = new Random(DateTime.Now.Millisecond);
                    var id   = rnd.Next();
                    var guid = Guid.NewGuid().ToString();
                    if (id % 2 == 0)
                    {
                        if (id % 4 == 0)
                        {
                            var message = new DomainMessage(guid, "exception");
                            await publisher.PublishAsync(message);
                        }
                        else
                        {
                            var message = new DomainMessage(guid, rnd.Next().ToString());
                            await publisher.PublishAsync(message);
                        }
                    }
                    else
                    {
                        var message = new AnotherDomainMessage(guid, rnd.Next().ToString(), "waddap indeed");
                        await publisher.PublishAsync(message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    await Task.Delay(500);
                }
            }
        }
 private static void RegisterServices(ContainerBuilder builder)
 {
     AutofacRegistrator.RegisterTypes(builder);
 }