Skip to content

Commit

Permalink
tweak configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Oct 18, 2023
1 parent c1b0e1d commit 5b477e5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,42 @@ IDataConfiguration dataConfiguration = new DataConfiguration(
);
```

Register with dependency injection

```c#
services.AddFluentCommand(builder => builder
.UseConnectionString(ConnectionString)
.UseSqlServer()
);
```

Register using a connection name from the appsettings.json

```c#
services.AddFluentCommand(builder => builder
.UseConnectionName("Tracker")
.UseSqlServer()
);
```

```json
{
"ConnectionStrings": {
"Tracker": "Data Source=(local);Initial Catalog=TrackerTest;Integrated Security=True;TrustServerCertificate=True;"
}
}
```

Register for PostgreSQL

```c#
services.AddFluentCommand(builder => builder
.UseConnectionName("Tracker")
.AddProviderFactory(NpgsqlFactory.Instance)
.AddPostgreSqlGenerator()
);
```

### Example

Query all users with email domain. Entity is automatically created from DataReader.
Expand Down
36 changes: 36 additions & 0 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,39 @@ var dataConfiguration = new DataConfiguration(
queryLogger: dataLogger
);
```

Register with dependency injection

```csharp
services.AddFluentCommand(builder => builder
.UseConnectionString(ConnectionString)
.UseSqlServer()
);
```

Register using a connection name from the appsettings.json

```csharp
services.AddFluentCommand(builder => builder
.UseConnectionName("Tracker")
.UseSqlServer()
);
```

```json
{
"ConnectionStrings": {
"Tracker": "Data Source=(local);Initial Catalog=TrackerTest;Integrated Security=True;TrustServerCertificate=True;"
}
}
```

Register for PostgreSQL

```csharp
services.AddFluentCommand(builder => builder
.UseConnectionName("Tracker")
.AddProviderFactory(NpgsqlFactory.Instance)
.AddPostgreSqlGenerator()
);
```
15 changes: 15 additions & 0 deletions src/FluentCommand.SqlServer/DataConfigurationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Data.SqlClient;

namespace FluentCommand;

public static class DataConfigurationBuilderExtensions
{
public static DataConfigurationBuilder UseSqlServer(this DataConfigurationBuilder builder)
{
builder
.AddProviderFactory(SqlClientFactory.Instance)
.AddSqlServerGenerator();

return builder;
}
}
6 changes: 2 additions & 4 deletions test/FluentCommand.SqlServer.Tests/DatabaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ protected override void ConfigureServices(HostBuilderContext context, IServiceCo

services.AddFluentCommand(builder => builder
.UseConnectionString(trackerConnection)
.AddProviderFactory(SqlClientFactory.Instance)
.AddSqlServerGenerator()
.UseSqlServer()
.AddDistributedDataCache()
);

var readOnlyConnection = trackerConnection + "ApplicationIntent=ReadOnly;";

services.AddFluentCommand<ReadOnlyIntent>(builder => builder
.UseConnectionString(readOnlyConnection)
.AddProviderFactory(SqlClientFactory.Instance)
.AddSqlServerGenerator()
.UseSqlServer()
.AddDistributedDataCache()
);
}
Expand Down

0 comments on commit 5b477e5

Please sign in to comment.