Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What's the use of ServiceStack?

Shulou Source: shulou.com Published: 2022-06-01 03:34:15 09月26日 Update

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.

Tags: Data data source database name article multiple character string attribute factory more service good practical information global content single that is article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Microsoft Docker MySQL