static void Main() { Log.Logger = new LoggerConfiguration() .Enrich.WithProperty("SourceContext", null) .WriteTo.LiterateConsole( outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message} ({SourceContext:l}){NewLine}{Exception}") .CreateLogger(); try { var builder = new ContainerBuilder(); builder.RegisterLogger(autowireProperties: true); builder.RegisterType<AcceptsLogViaCtor>().As<IExample>(); builder.RegisterType<AcceptsLogViaProperty>().As<IExample>(); using (var container = builder.Build()) { var examples = container.Resolve<IEnumerable<IExample>>(); foreach (var example in examples) { example.Show(); } } } catch (Exception ex) { Log.Error(ex, "Unhandled error"); } }
public void Configuration(IAppBuilder app) { ConfigureLogger(); var builder = new ContainerBuilder(); builder.RegisterLogger(); builder.RegisterByAttributes(typeof (Startup).Assembly); builder.RegisterAssemblyModules(typeof (Startup).Assembly); builder.RegisterHubs(typeof (Startup).Assembly); var container = builder.Build(); // config hubs var config = new HubConfiguration(); config.Resolver = new AutofacDependencyResolver(container); app.UseJwtTokenAuthentication(container.Resolve<IssuerSetting>(), container.Resolve<AudienceSetting>(), container.Resolve<ClientSecretSetting>(), container.Resolve<ICurrentUserProvider>()); app.MapSignalR(config); app.UseNancy(new NancyOptions { Bootstrapper = new NancyBootstrapper(container) }); app.UseStageMarker(PipelineStage.MapHandler); app.UseCors(CorsOptions.AllowAll); JsonSettings.RetainCasing = false; SeedData(container); }
static void Main(string[] args) { var builder = new ContainerBuilder(); Log.Logger = new LoggerConfiguration() .WriteTo.Seq("http://localhost:5341") .CreateLogger(); builder.RegisterLogger(Log.Logger, true); var container = builder.Build(); var v = new MyType(container); v.Log(); Console.ReadLine(); }
public void ConfigureAutofac(IAppBuilder app) { var builder = new ContainerBuilder(); var logger = ConfigureLogging(); builder.RegisterLogger(logger); builder.RegisterControllers(typeof(MvcApplication).Assembly); //builder.RegisterType<CarManager>().As<ICarManager>(); //builder.RegisterType<EnquiryManager>().As<IEnquiryManager>(); //builder.RegisterType<CommentManager>().As<ICommentManager>(); //builder.RegisterType<CarContext>().As<CarContext>(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
private void ConfigureIoC() { var builder = new ContainerBuilder(); var config = GlobalConfiguration.Configuration; var assemblies = new[] { Assembly.GetExecutingAssembly() }; builder.RegisterApiControllers(assemblies); builder.RegisterLogger(); builder.RegisterAssemblyTypes(assemblies) .AsClosedTypesOf(typeof(IMapper<,>)) .AsImplementedInterfaces() .InstancePerDependency(); var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); }
protected void Application_Start() { var builder = new ContainerBuilder(); // Get your HttpConfiguration. var config = GlobalConfiguration.Configuration; // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); // OPTIONAL: Register the Autofac filter provider. builder.RegisterWebApiFilterProvider(config); builder.RegisterType<LogController>().InstancePerRequest(); builder.RegisterType<SessionController>().InstancePerRequest(); builder.RegisterType<Logger>(); builder.RegisterLogger(); builder.RegisterModule<Settings.ConfigurationModule>(); // Set the dependency resolver to be Autofac. var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); GlobalConfiguration.Configure(WebApiConfig.Register); // var container = builder.Build(); //configure logger container.Resolve<Logger>(); // DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // Create the depenedency resolver. // var resolver = new AutofacWebApiDependencyResolver(container); // Configure Web API with the dependency resolver. // GlobalConfiguration.Configuration.DependencyResolver = resolver; }
protected override void Load(ContainerBuilder builder) { builder.RegisterLogger(); }