Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the use of ServiceStack?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what is the use of ServiceStack for you. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

In ServiceStack development, the connection to the database is defined in AppHost, which can be used directly in Service, which is the convenience of a single data source. If there are multiple database connections, it needs to be defined, and attributes are used to distinguish them in Service.

Multiple data sources are defined in AppHost, and the data sources are distinguished according to their names. Of course, default data sources are still needed.

/ / add a default data source based on the connection string, which is sqlserver

Var connStr = appSettings.GetString ("sqlcon")

Container.Register (c = > new OrmLiteConnectionFactory (connStr, SqlServerDialect.Provider))

/ / find the global data source factory in the system

Var dbFactory = container.Resolve () as OrmLiteConnectionFactory

Once you find the data source factory, you can add a new database source.

/ / use the new database connection string

ConnStr = appSettings.GetString ("custompsconinfo")

/ / Register a new data source, whose name is custompsconinfo

DbFactory.RegisterConnection ("custompsconinfo", connStr, SqlServerDialect.Provider)

Following the steps above, the data source is added. For the default data source in the service, there is no need to add anything else. If you use a data source named custompsconinfo, you need to add attribute headers on the Service.

[ConnectionInfo (NamedConnection = "custompsconinfo")]

Public class SourceService: Service

After adding this header, the database used in the service is the connection information of custompsconinfo.

This is the end of this article on "what's the use of ServiceStack". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report