Easily add logging to your Akka.NET based system to effectively monitor production applications and use dependency injection to ensure your actors remain loosely coupled and adhere to object oriented best practices.
Akka.NET makes building concurrent and distributed applications easier. As with other architectures, Akka.NET based systems need effective logging for the monitoring and diagnosing of systems when deployed to production. Just because we use Akka.NET to get the benefits of the Actor Model, it doesn’t mean that best practices for object construction and dependencies such as dependency injection should be ignored. By the end of this course, you’ll understand how to implement effective logging in your Akka.NET system and how to use dependency injection to ensure the services your actors depend on are still provided in a loosely coupled and configurable way.
Introduction Hi, I'm Jason Roberts from Pluralsight. Welcome to this course on Implementing Logging, and Dependency Injection in Akka. NET. The Actor Model Akka. NET, gives us an easier model to create concurrent, distributed, fault tolerant, and self-healing systems, but just because we're using Akka. NET, and making use of Actors and Messages, it doesn't mean we don't have to consider support related items. Whether this be supporting the running Actor system when it's in production, or supporting ongoing development in maintenance of the code base over time, by using good programming practices. We've all been in the unfortunate situation of having a production problem, and having to work under considerable pressure to get it fixed. One of the things that can make these situations more stressful, Is a lack of useful log information. When it comes to production use, we need some insight into what's going on. Without logging, we have very little information to use if we need to diagnose a potential problem. Even if we don't have a production fault, good logging enables us to get insights into how our Actor system is running. These insights can be used by the development team to plan future work, and prevent potential problems from occurring in the future. Insights can also be a benefit to the business, allowing them to get information on areas such as what features are being used the most. Dependency Injection is something that allows us to keep our Actors loosely coupled for any Dependencies they need, and also contribute to keeping the code base loosely coupled easier to change in the future, and potentially more testable. By the end of this course, you'll know how to make your Akka. NET system more production ready by implementing logging, and also more maintainable over time, by implementing Dependency Injection.
Implementing Logging Hi! Welcome back. Getting a phone call in the middle of the night because there's a production problem is never pleasant. Effective logging that's easily queriable can mean the difference between having to drive to the office and spend hours investigating, or simply firing up the VPN, quickly determining the cause, and fixing it. With effective, queriable logging, we can be back in our nice, warm bed sooner. Akka. NET supports a variety of methods by which to write log messages, from simply writing to the console window or text files, right up to storing them in a database or custom log store. In this module, we'll start off by looking at the different log output choices that we can use with Akka. NET, so we'll see how different options allows us to write to destinations such as the console, files, or databases, and also the different logging levels that Akka. NET supports. We'll learn about the HOCON configuration options when we're dealing with logging, and how to configure things such as the minimum log level. Next, we'll get started and change the demo application from Module One, to use the built-in StandardOutLogger. When we do this, our log messages are automatically output to the console window. Next, we'll see how we can introduce Nlog into our actor system, and instead use NLog to write log output messages. We'll configure NLog to write to a target log file, and we'll see, when we do this, we don't actually have to go and change our logging code, we just need to make some configuration changes. Finally, to wrap up this module, we'll see how we can replace NLog with Serilog. While Serilog supports a number of output formats, in the demo, we'll see how we can get Serilog to write to Seq, and then we'll see how we can query Seq to get an idea of how our actor system is behaving.
Implementing Dependency Injection Hi, welcome back to this module on Implementing Dependency Injection. So in the previous module, we made our system more production-supportable by adding logging, but just because we're using the high level abstraction of actors and messages, doesn't mean we don't need to consider other OO techniques, such as Dependency Injection, to keep our codebase more loosely coupled and maintainable over time. When we're using Dependency Injection in Akka. NET to create a more maintainable, loosely coupled codebase, we need to ensure that the Dependency Injection container we're using is going to use a compatible lifecycle scope when it supplies instances of objects to Akka. NET. In this module, we're going to start off by looking at some of the Dependency Injection Container choices we have when we want to implement DI in Akka. NET. We'll next get a high level overview of the steps required to use one of these Dependency Injection Containers in our Akka. NET actor system. Next, we'll go and refactor one of our actors to remove the concrete dependency and type coupling and to instead take a dependency as a constructor parameter. Next, we'll see how we can configure AutoFac, CastleWindsor and Ninject in our Akka. NET system. Finally, we'll consider how the different Lifecycle scopes of Dependency Injection Containers interact with Akka. NET's management of actor instances, and we'll also see that when we're using DI, we need to be careful that we're not injecting anything that's going to allow shared mutable state between our actors.