Skip to content

Instantly share code, notes, and snippets.

View fasetto's full-sized avatar
😈

Serkan Bircan fasetto

😈
View GitHub Profile
[Route("/hello/{Name}", "GET")]
public class HelloRequest : IReturn<HelloResponse>
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
public class AppHost : AppSelfHostBase
{
public AppHost() :
base("HelloService Self-Host", typeof(HelloService).Assembly)
{
}
public override void Configure(Container container)
{
[TestMethod]
public void ResponseTest()
{
// Arrange
var client = new JsonHttpClient("http://127.0.0.1:1337/");
// Act
string response = client.Get<HelloResponse>("/hello/SERKAN").Result;
// Ya da..
using System;
namespace ServiceStackSample.ConsoleHost
{
class Program
{
static void Main(string[] args)
{
string listeningOn = "http://127.0.0.1:1337/";
public class User : EntityBase
{
[BsonElement("firstname")]
public string FirstName { get; set; }
[BsonElement("lastname")]
public string LastName { get; set; }
[BsonElement("email")]
public string Email { get; set; }
public abstract class EntityBase
{
[BsonId]
public ObjectId Id { get; set; }
}
public interface IRepository<TEntity> where TEntity : EntityBase
{
Task AddNewAsync(TEntity entity);
Task<bool> UpdateAsync(ObjectId id, string field, string value);
Task<TEntity> GetByIdAsync(ObjectId id);
Task<IEnumerable<TEntity>> GetByFieldAsync(string field, string value);
Task<long> DeleteAllAsync();
}
public class MongoDataContext
{
public IMongoDatabase Database { get; }
public MongoDataContext(string connectionString)
{
var mongoUrl = new MongoUrl(connectionString);
IMongoClient client = new MongoClient(mongoUrl);
Database = client.GetDatabase(mongoUrl.DatabaseName);
public abstract class MongoRepository<TEntity> : IRepository<TEntity>
where TEntity : EntityBase
{
protected abstract IMongoCollection<TEntity> Collection { get; }
public MongoRepository(MongoDataContext dataContext)
{
}
public virtual async Task AddNewAsync(TEntity entity)
public class UserRepository : MongoRepository<User>
{
private readonly MongoDataContext _dataContext;
protected override IMongoCollection<User> Collection => _dataContext.Database.GetCollection<User>("users");
public UserRepository(MongoDataContext dataContext)
: base(dataContext)
{
_dataContext = dataContext;
}