简体   繁体   English

我想在我的配置文件 (ASP.NET / C#) 中存储类名

[英]I want to store class names in my configuration file (ASP.NET / C#)

I'm developing a service that'll be provide messages to a calling UI based on conditions that exist per message.我正在开发一项服务,该服务将根据每条消息存在的条件向调用 UI 提供消息。

I have a json file that stores all the different possible messages the UI can receive and I expect that file to grow throughout the application's lifetime (ie I plan to add new message configurations)我有一个 json 文件,用于存储 UI 可以接收的所有不同可能的消息,我希望该文件在应用程序的整个生命周期中不断增长(即我计划添加新的消息配置)

The problem is each message has a different condition on whether it should be included in the response and these conditions rely on a downstream call being made to some DB or other service and then logic that processes those downstream calls to resolve whether a condition is true or false.问题是每条消息对于是否应该包含在响应中都有不同的条件,这些条件依赖于对某个数据库或其他服务进行的下游调用,然后是处理这些下游调用的逻辑,以解决条件是否为真或错误的。

I want to have each message in my configuration file to have a value that resolves to a class in my code so that when the endpoint is called, I can just call a "resolve" method passing that "message configuration" ie the resolve method calls the class associated to that message (and it's condition resolution method) and makes all the necessary calls to downstream services.我想让我的配置文件中的每条消息都有一个解析为我的代码中的类的值,这样当端点被调用时,我可以调用一个传递“消息配置”的“解析”方法,即解析方法调用与该消息关联的类(及其条件解析方法)并对下游服务进行所有必要的调用。

Is there a way to have each of my messages have classes associated to them in my json configuration file?有没有办法让我的每条消息在我的 json 配置文件中都有与之关联的类? Am I missing a much easier way to implement this?我错过了一个更简单的方法来实现这个吗?

As I can see, when you need to add a new message to the application, you have to add it to the configuration file and additionally define a separate class with conditions.如我所见,当您需要向应用程序添加新消息时,您必须将其添加到配置文件中,并另外定义一个带有条件的单独类。 Right?正确的? If your answer is yes, message file (json) won't save you from builds and deployments over and over again.如果您的回答是肯定的,消息文件 (json) 将不会一次又一次地使您免于构建和部署。 You can move your messages into classes that implement the interface.您可以将消息移动到实现该接口的类中。 Then simply register them as a collection and process messages through that collection.然后只需将它们注册为集合并通过该集合处理消息。 The message and conditions will be resolved without any "magic" tricks.消息和条件将在没有任何“魔法”技巧的情况下解决。 Of course, for a new message type, you have to declare a new class with the same interface, new message, and the appropriate logic.当然,对于新的消息类型,您必须声明一个具有相同接口、新消息和相应逻辑的新类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM