Working with events and observers is one of the main ways to extend Magento's functionality.The implementation of events and observers in Magento 2 is based on the publish-subscribe pattern.Using Events and Observers You can run your custom code in response to a specific Magento event or even a custom event.To understand how this works, let's dispatch some custom event in a custom controller.First of all, let's add the event manager interface.Let's call it eventManager.Let's remove unnecessary qualifier.And let's add all the necessary parameters to our class.Now we can use the event manager to dispatch custom events.Let's add two custom events here.And here.To dispatch custom events, we only need to specify the name of the event.That's it.But sometimes it can be very useful if we can add some values from this place to our event manager.In this case we need to specify the event name and we can also add someValue to the event observer.Now we can subscribe to these two events.another custom event and some custom eventAs you may remember, Magento supports the PSR-4 standard, so the folder structure can be very flexible.But as per Magento best practice, it is better to use Observer name for observers folder or plugin name for plugins folders.Let's create something like TestObserver.The observer can be configured to listen for specific events in events dot xmlWe can get an example from the Magento_Catalog module.Let's add it to the frontend area.And let's delete unnecessary data.As you can see, we need to specify the name of the event.In our case it could be another_custom_event or some_custom_event.We also need to specify a unique name for the observer.And the observer class.You can see that here we have an additional attribute.shared is falseBy default, "Shared" is set to true.if shared is true then there is only one instance of this class, as in the Singleton pattern, the object manager creates it on the first request, and requesting the class again returns the same instance.But if we change "shared" to "false", the object manager will create a new instance of the class for each requestso let's leave it as "false"And let's change our name from "customer_login" to "another_custom_event".Let's create some unique observer nameand let's add the class name of our observer.Let's add some code to the observer class, but please note that according to Magento best practices, all values, including objects passed to the event, should not be modified in the event observer. Instead, plugins should be used to modify the input or output of the function.So we can get this value from here.Let's get this valueWe have to get someValue.Now we can use this value.Let's add some additional information.Let's clear the cache and check it.Here we have the "set" method.After that we have information from the Observer and "some test value" from that "Set" method.Works fine. As you can see, we can add custom events and run any custom code in response to a specific event, and this can be really useful.Let's check the dispatch method.As you can see, we can check the list of triggered events in the profiler.Let's enable Magento Profiler and try to check the list of Magento events in the log file.To enable the profiler we need to run the following command bin/magento dev profiler enableLet's take a look at our storefrontand scroll down to the bottom of the page.As you can see, we have a lot of default Magento events here.It's about 19 events and it can be really usefulFor example, you can use the very popular checkout_submit_all_after eventLet's find it.This event is dispatched after a successful order and we can use it to send some special emails.For example, with order information.But remember that all values, including the object passed to the event, must not be modified in the event observer.Instead, it would be better to use plugins to modify the input or output of a function.But for other purposes you can use events, and this can be really useful.