The Lifecycle Objects on CDI
When we talk about a system OOP, we, naturally, work with Objects; those objects exist in memory until you destroy them. Object lifecycle routines allow the creation and destruction of object references. In enterprise system architecture design, we can imagine several cases, such as a Connection instance, where when we create an instance, we need to open the connection, and we don't need this instance. We can close and then destroy it. Lifecycle methods associated with an object will enable you to control what happens when an object is created or destroyed. We can break the life of an object into three phases: start, usage, and trashing. CDI allows you to create and handle objects; by default, CDI will create an instance using the constructor; however, sometimes, there is no reason for it. Therefore, we have the Vetted annotation to teach CDI to don't use this way. CDI is brilliant, and I will learn it very quickly. On the other hand, we have trouble teaching CDI to create an object in a different way. It does not make sense only with the entity that we design in the same package or project but also with integration with libraries that already do exist. To make it possible, CDI provides a Produces annotation where it will explain to CDI to use this instance when someone inside the container needs it. If you are familiar with Spring, it is similar to combining two annotations inside the platform, Bean and Configuration. As an object, a managed bean inside CDI, we can express the lifecycle of this object. We need to put the same CDI annotation scoped we learned previously on the Produces method. Request Scoped Application Scoped Session Scoped Conversation Scoped A good example would be a system that uses the money-API, and we want to define a currency available to the whole system. It does not make sense to the client to know which currency the system uses or where this currency comes from. It only needs to inject and then use this currency. The solution is to explore the producer's power to make it unrestricted to the whole system. The last step in an object lifecycle is when we don't need anymore. E.g., When the connection needs to be closed, or we need to the registry or count a resource we don't need anymore. CDI has the Disposes annotation, in analogy, is the opposite of Produces. Therefore, we use Produces to build up and Dispose to destroy. This video will explain more details about the object's lifecycle with CDI where you can take benefits of this robust framework to control objects/resources. We'll explain how to ignore beans with Vetted annotation and make up and destroy with Produce and Dispose annotations, respectively. The lifecycle objects on CDI Topics Covered In this Video: 0:00 Introduction to The Lifecycle Objects on CDI 5:35 Integration 9:15 Disposes 11:15 Injection Point #lifecycleobjectsoncdi #integration #OtavioSantana
When we talk about a system OOP, we, naturally, work with Objects; those objects exist in memory until you destroy them. Object lifecycle routines allow the creation and destruction of object references. In enterprise system architecture design, we can imagine several cases, such as a Connection instance, where when we create an instance, we need to open the connection, and we don't need this instance. We can close and then destroy it. Lifecycle methods associated with an object will enable you to control what happens when an object is created or destroyed. We can break the life of an object into three phases: start, usage, and trashing. CDI allows you to create and handle objects; by default, CDI will create an instance using the constructor; however, sometimes, there is no reason for it. Therefore, we have the Vetted annotation to teach CDI to don't use this way. CDI is brilliant, and I will learn it very quickly. On the other hand, we have trouble teaching CDI to create an object in a different way. It does not make sense only with the entity that we design in the same package or project but also with integration with libraries that already do exist. To make it possible, CDI provides a Produces annotation where it will explain to CDI to use this instance when someone inside the container needs it. If you are familiar with Spring, it is similar to combining two annotations inside the platform, Bean and Configuration. As an object, a managed bean inside CDI, we can express the lifecycle of this object. We need to put the same CDI annotation scoped we learned previously on the Produces method. Request Scoped Application Scoped Session Scoped Conversation Scoped A good example would be a system that uses the money-API, and we want to define a currency available to the whole system. It does not make sense to the client to know which currency the system uses or where this currency comes from. It only needs to inject and then use this currency. The solution is to explore the producer's power to make it unrestricted to the whole system. The last step in an object lifecycle is when we don't need anymore. E.g., When the connection needs to be closed, or we need to the registry or count a resource we don't need anymore. CDI has the Disposes annotation, in analogy, is the opposite of Produces. Therefore, we use Produces to build up and Dispose to destroy. This video will explain more details about the object's lifecycle with CDI where you can take benefits of this robust framework to control objects/resources. We'll explain how to ignore beans with Vetted annotation and make up and destroy with Produce and Dispose annotations, respectively. The lifecycle objects on CDI Topics Covered In this Video: 0:00 Introduction to The Lifecycle Objects on CDI 5:35 Integration 9:15 Disposes 11:15 Injection Point #lifecycleobjectsoncdi #integration #OtavioSantana