public static QuickApplication AddMongoService(this QuickApplication quickApp, string serviceName = null, Action <ServiceDescriptor> configureService = null) { if (serviceName == null) { serviceName = "mongodb"; } quickApp.AddService(new ServiceDescriptor(serviceName, typeof(IMongoDbDatabaseService), () => quickApp.ServiceProvider.GetService <IMongoDbDatabaseService>() ), configureService); return(quickApp); }
public static QuickApplication AddBasicAuthService(this QuickApplication quickApp, string serviceName = null, Action <ServiceDescriptor> configureService = null) { if (serviceName == null) { serviceName = "auth"; } quickApp.AddService( new ServiceDescriptor(serviceName, typeof(IBasicCookieAuthentication), () => quickApp.ServiceProvider.GetService <IBasicCookieAuthentication>()) { RequireAuth = false }, configureService ); return(quickApp); }
private void QuickAppConfig(QuickApplication quickApp, IApplicationBuilder app) { quickApp .AddMongoService("mongodb") .AddBasicAuthService("auth") .AddInterceptor("mongodb", "InsertOne", Moment.Before, context => { context.Arguments.document.name += " 2"; context.Arguments.document.userId = 44; }) .AddInterceptor("mongodb", "Find", Moment.After, context => { context.Result.Add(new { name = "From", surname = "After Find Interceptor" }); }) .AddInterceptor("mongodb", new MongoInterceptorImplementingInterface()) .AddInterceptor("mongodb", new MongoInterceptorUsingMethodsNames()); app.UseQuickAppBasicAuth <AuthUser>(); }
public static void Main(string[] args) { var app = new QuickApplication(null); app.AddService(new ServiceDescriptor(typeof(Service1), () => new Service1())); app.AddService(new ServiceDescriptor(typeof(IMongoDbDatabaseService), () => new MongoDbDatabaseService("mongodb://localhost:27017", "prueba"))); app.CallServiceMethod("MongoDbDataBaseService", "InsertOne", new { collectionName = "People", document = new { nombre = "Javier", surName = "Ros" } }); //app.CallServiceMethod("MongoDbDataBaseService", "InsertMany", new //{ // collectionName = "People", // documents = new[] // { // new { // nombre = "Pepito", // surName = "Lucas" // }, // new { // nombre = "Juan", // surName = "Moreno" // } // } //}); //Console.WriteLine(app.CallServiceMethod("MongoDbDataBaseService", "Count", // new // { // collectionName = "People" // })); //Console.WriteLine(app.CallServiceMethod("MongoDbDataBaseService", "Get", // new // { // collectionName = "People", // id = "5813b9e1ad89ee106091bbfc" // })); //foreach (var doc in (IEnumerable<dynamic>)app.CallServiceMethod("MongoDbDataBaseService", "Find", // new // { // collectionName = "People", // skip = 0, // take = 6, // filter = JsonConvert.DeserializeObject(" { 'nombre': { '$in': ['Javier', 'Juan', 'Pepito'] } }"), // order = new { surName = 1 }, // projection = new { _id = 0 } // })) //{ // Console.WriteLine(doc); //} //app.CallServiceMethod("MongoDbDataBaseService", "UpdateOne", // new // { // collectionName = "People", // filter = new { nombre = "Javier" }, // update = JsonConvert.DeserializeObject<dynamic>("{'$set': { 'role': 'admin'}}") // }); //app.CallServiceMethod("MongoDbDataBaseService", "UpdateMany", // new // { // collectionName = "People", // filter = JsonConvert.DeserializeObject(" { 'nombre': { '$in': ['Javier', 'Juan', 'Pepito'] } }"), // update = JsonConvert.DeserializeObject<dynamic>("{'$set': { 'age': '18'}}") // }); //app.CallServiceMethod("MongoDbDataBaseService", "DeleteOne", // new // { // collectionName = "People", // filter = JsonConvert.DeserializeObject(" { 'nombre': { '$in': ['Juan', 'Pepito'] } }"), // }); Console.WriteLine( app.CallServiceMethod("service1", "Saludar", JObject.FromObject(new { nombre = 9 })) .ToString()); Console.ReadKey(); }