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
[Route("/hello/{Name}", "GET")] | |
public class HelloRequest : IReturn<HelloResponse> | |
{ | |
public string Name { get; set; } | |
} | |
public class HelloResponse | |
{ | |
public string Result { get; set; } | |
} |
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
public class AppHost : AppSelfHostBase | |
{ | |
public AppHost() : | |
base("HelloService Self-Host", typeof(HelloService).Assembly) | |
{ | |
} | |
public override void Configure(Container container) | |
{ |
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
[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.. |
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
using System; | |
namespace ServiceStackSample.ConsoleHost | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string listeningOn = "http://127.0.0.1:1337/"; |
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
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; } |
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
public abstract class EntityBase | |
{ | |
[BsonId] | |
public ObjectId Id { get; set; } | |
} |
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
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(); | |
} |
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
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); |
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
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) |
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
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; | |
} |
OlderNewer