How to configure the data service and get its authority from anywhere in the application

DataServiceProvider.DataService is service data, which is initialized based on the settings specified in the configuration file (App.cobfig or Web.config). Thus, DataServiceProvider.DataService is service data by default.

Algorithm initialization DataServiceProvider.DataService

Initialization DataServiceProvider.DataService use the following algorithm (initialization, if there is a cached value, or is the flag that should always return a new data service):

1.Attempts to resolve type service data through Unity. For example, to use MSSQLDataService in the configuration file you want to add the following definition:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
  </configSections>

  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <container>
    <register type="ICSSoft.STORMNET.Business.IDataService, ICSSoft.STORMNET.Business"
        mapTo="ICSSoft.STORMNET.Business.MSSQLDataService, ICSSoft.STORMNET.Business.MSSQLDataService">
      <constructor/>
    </register>
    </container>
  </unity>
</configuration>

2.If the type of data service was resolved via Unity, is determined by the connection string. First, in the web style, then win in style.

web style:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="SomeConnectionStringName" connectionString="SERVER=server;Trusted_connection=yes;DATABASE=dbname;" />
  </connectionStrings>
  <appSettings>
    <add key="DefaultConnectionStringName" value="SomeConnectionStringName"/>
  </appSettings>
</configuration>

win-style:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="CustomizationStrings" value="SERVER=server;Trusted_connection=yes;DATABASE=dbname;"/>
  </appSettings>
</configuration>

3.Next, get DataServiceProvider.DataService occurs in the old algorithm. Type service data - setting DataServiceType in the configuration file. And the connection string is determined depending on in which mode the app, web or win.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="DataServiceType" value="ICSSoft.STORMNET.Business.MSSQLDataService, ICSSoft.STORMNET.Business.MSSQLDataService" />
  </appSettings>
</configuration>

connection String

You can read more about connection strings for LocalDB can be read in this article.

About the connection strings in General can be found in msdn.