Package: pydiator-core
Installationhttps://pypi.org/project/pydiator-core/add your requirements.txtpydiator-coreor run thepip install pydiator-corecommandExamplesDirectly :https://github.com/ozgurkara/pydiator-core/blob/master/examples/main.pyFastapi :https://github.com/ozgurkara/fastapi-pydiatorWhat is the pydiator?Pydiator is an in-app communication method.It provides that developing the code as an aspect. Also, it supports clean architecture infrastructureIt is using design patterns such as chain of responsibility, mediator, singleton.Pydiator provides which advantages to developers and project?TestableUse case supportAspect programming (Authorization, Validation, Cache, Logging, Tracer etc.) supportClean architectureExpandable architecture via pipelineIndependent frameworkSOLID principlesHas publisher subscriber infrastructureHow it works?Pydiator knows 4 object types.
These are;1- Request objectIs used for calling the use case.It should be inherited fromBaseRequestclassGetSampleByIdRequest(BaseRequest):def__init__(self,id:int):self.id=id2- Response objectIs used for returning from use caseIt should be inherited fromBaseResponseclassGetSampleByIdResponse(BaseResponse):def__init__(self,id:int,title:str):self.id=idself.title=title3- Use CaseIncludes logic codesIt should be inherited fromBaseHandlerIt takes one parameter to handle. The parameter should be inheritedBaseRequestclassGetSampleByIdUseCase(BaseHandler):asyncdefhandle(self,req:GetSampleByIdRequest):# related codes are here such as businessreturnGetSampleByIdResponse(id=req.id,title="hello pydiatr")What is the relation between these 3 object types?Every use case object only knows a request objectEvery request object is only used by one use case objectHow is the use case run?Should be had a particular map between the request object and the use case object.Mapping example;defset_up_pydiator():container=MediatrContainer()container.register_request(GetSampleByIdRequest,GetSampleByIdUseCase())#container.register_request(xRequest, xUseCase())pydiator.ready(container=container)Calling example;awaitpydiator.send(GetByIdRequest(id=1))orloop=asyncio.new_event_loop()response:GetByIdResponse=loop.run_until_complete(pydiator.send(GetByIdRequest(id=1)))loop.close()print(response.to_json())4- PipelineThe purpose of the pipeline is to manage the code as an aspect.
For instance, you want to write a log for the request and the response of every use case. You can do it via a pipeline easily. You can see the sample log pipeline at this link.You can create a lot of pipelines such as cache pipeline, validation pipeline, tracer pipeline, authorization pipeline etc.Also, you can create the pipeline much as you want but you should not forget that every use case will be used in this pipeline.You can add the pipeline to pipelines such as;defset_up_pydiator():container=MediatrContainer()container.register_pipeline(LogPipeline())#container.register_pipeline(xPipeline())pydiator.ready(container=container)How can you write a custom pipeline?Every pipeline  should be inheritedBasePipelineSample pipelineclassSamplePipeline(BasePipeline):def__init__(self):passasyncdefhandle(self,req:BaseRequest)->object:# before executed pipeline and uce caseresponse=awaitself.next().handle(req)# after executed next pipeline and use casereturnresponseHow to use the notification-subscriber featureWhat is the notification-subscriber feature?This feature runs as pub-sub design pattern.What is the pub-sub pattern?publish-subscribe is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead, categorize published messages into classes without knowledge of which subscribers if any, there may be. Similarly, subscribers express interest in one or more classes and only receive messages that are of interest, without knowledge of which publishers, if any, there are.How to use this pattern with the pydiator?You can see the details that via this linkhttps://github.com/ozgurkara/pydiator-core/blob/master/examples/notification.pydefset_up_pydiator():container=MediatrContainer()container.register_notification(SampleNotification,[Sample1Subscriber(),Sample2Subscriber(),Sample3Subscriber()])pydiator.ready(container=container)if__name__=="__main__":set_up_pydiator()loop=asyncio.new_event_loop()loop.run_until_complete(pydiator.publish(SamplePublisherRequest(id=1)))loop.close()How to run the Unit Testsinstall tests/requirements.txtpytest tests/