Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                DapperConfiguration.Initialize();
                ConnectionProvider provider = new ConnectionProvider();
                UserAccountDapper  dapper   = new UserAccountDapper();

                // UserAccountBroker userDataBroker = new UserAccountBroker(provider);
                //UserAccount user = userDataBroker.GetUserAccount("florian", "pwd");
                UserAccount user = null;
                IEnumerable <UserAccount> accounts = dapper.GetAllContact(provider.GetConnection(), 1);

                user = dapper.GetUserAccount(provider.GetConnection(), "florian", "pwd");

                if (user != null)
                {
                    Console.WriteLine(user.Firstname);
                    Console.WriteLine(user.Lastname);
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            Console.Read();
        }
Beispiel #2
0
        private static void AddDapper(this IServiceCollection services, string connectionString)
        {
            services.AddTransient(typeof(IRepository <>), typeof(DapperRepository <>));
            services.AddScoped <IUnitOfWork, DapperUnitOfWork>();
            services.AddTransient <IQueryService>(provider => {
                var dapperQueryService = new DapperQueryService(provider.GetRequiredService <IDbConnectionFactory>(), connectionString);
                return(dapperQueryService);
            });
            services.AddSingleton <IDbConnectionFactory, DapperDbConnectionFactory <SqlConnection> >();
            services.AddTransient <IDbConnection>(provider => { return(new SqlConnection(connectionString)); });

            DapperConfiguration.Initialize();
        }
Beispiel #3
0
        public static void Register(HttpConfiguration config)
        {
            // Web-API-Konfiguration und -Dienste
            //TODO Frage?????
            DapperConfiguration.Initialize();
            // Web-API-Routen
            config.MapHttpAttributeRoutes();
            //routeTemplate: "api/{controller}/{id}",
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(
                new MediaTypeHeaderValue("text/html"));
        }
Beispiel #4
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            DapperConfiguration.Initialize();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(
                new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"));
        }