-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release validation and update docs (#93)
* update docs and validation * preparing release for core 2.0.0-alpha.6
- Loading branch information
1 parent
060ecb7
commit caa1c7b
Showing
24 changed files
with
233 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,41 @@ | ||
# Services | ||
|
||
If your application requires additional services like a database or Redis, you'll need to create a class that implements the `DoxService` interface and then register it with Dox. Since Dox operates with isolates (multi-threading), these extra services must be passed to each isolate to ensure their availability on all isolates. | ||
If your application requires additional services like a database, auth etc.., you'll need to create a class that implements the `DoxService` interface and then register it with Dox. Since Dox operates with isolates (multi-threading), these extra services must be passed to each isolate to ensure their availability on all isolates. | ||
|
||
### Example with redis | ||
### Example with auth | ||
|
||
=== "Redis service" | ||
=== "AuthService" | ||
|
||
```dart | ||
class Redis implements DoxService { | ||
/// Declare as Singleton reuse connection | ||
static final Redis _i = Redis._internal(); | ||
factory Redis() => _i; | ||
Redis._internal(); | ||
|
||
late Command command; | ||
|
||
class AuthService implements DoxService { | ||
@override | ||
Future<void> setup() async { | ||
RedisConnection conn = RedisConnection(); | ||
String tls = Env.get('REDIS_TLS', 'false'); | ||
String host = Env.get('REDIS_HOST', 'localhost'); | ||
int port = int.parse(Env.get('REDIS_PORT', '6379')); | ||
|
||
if (tls == 'true') { | ||
Redis().command = await conn.connectSecure(host, port); | ||
} else { | ||
Redis().command = await conn.connect(host, port); | ||
} | ||
|
||
String username = Env.get('REDIS_USERNAME', ''); | ||
String password = Env.get('REDIS_PASSWORD', ''); | ||
|
||
if (username.isNotEmpty && password.isNotEmpty) { | ||
await Redis().command.send_object( | ||
<dynamic>['AUTH', username, password], | ||
); | ||
} | ||
void setup() { | ||
Auth.initialize(AuthConfig( | ||
/// default auth guard | ||
defaultGuard: 'web', | ||
|
||
/// list of auth guards | ||
guards: <String, AuthGuard>{ | ||
'web': AuthGuard( | ||
driver: JwtAuthDriver(secret: SecretKey(Env.get('APP_KEY'))), | ||
provider: AuthProvider( | ||
model: () => User(), | ||
), | ||
), | ||
}, | ||
)); | ||
} | ||
} | ||
``` | ||
|
||
##### | ||
=== "Register into dox `bin/server.dart`" | ||
=== "Register into dox `app/config/services.dart`" | ||
|
||
```dart | ||
void main() async { | ||
/// Initialize Dox | ||
Dox().initialize(Config()); | ||
```dart | ||
List<DoxService> services = <DoxService>[ | ||
... /// other services | ||
AuthService, | ||
]; | ||
``` | ||
|
||
/// register redis service | ||
Dox().addService(Redis()); | ||
|
||
/// start dox http server | ||
await Dox().startServer(); | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.