Beispiel #1
0
        public static void Main(string[] args)
        {
            UnityBootStrap();
            //var userRepository = Microsoft.Practices.Unity.UnityContainerExtensions.Resolve<IUserRepository>(container);
            var userRepository = ContainerExtensions.Resolve <IUserRepository>(container);

            Console.WriteLine("Call Stack of Layers when invoking GetUserFullName(0):\n {0} ", userRepository.GetUserFullName(0));
        }
Beispiel #2
0
        public override void Configure(Container containerFunq)
        {
            new Module().Init(UnityServiceLocator.Instance, ConfigurationManager.ConnectionStrings["MKWebDev"]);

            // Ensuring that Guids always serialize with the hyphens
            JsConfig <Guid> .RawSerializeFn  = guid => "\"" + guid.ToString("D") + "\"";
            JsConfig <Guid?> .RawSerializeFn = guid => guid.HasValue ? "\"" + guid.Value.ToString("D") + "\"": null;

            var notificationService = UnityServiceLocator.Instance.Resolve <INotificationService>();

            notificationService.SetBaseUrl(new Uri("http://www.example.net"));

            var container = UnityServiceLocator.Instance;

            containerFunq.Adapter = new UnityContainerAdapter(container, new Logger());

            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new CustomCredentialsAuthProvider(UnityContainerExtensions.Resolve <ICommandBus>(container),
                                                  UnityContainerExtensions.Resolve <IAccountDao>(container),
                                                  UnityContainerExtensions.Resolve <IPasswordService>(container),
                                                  UnityContainerExtensions.Resolve <IServerSettings>(container)),
                new CustomFacebookAuthProvider(UnityContainerExtensions.Resolve <IAccountDao>(container)),
                new CustomTwitterAuthProvider(UnityContainerExtensions.Resolve <IAccountDao>(container))
            }));
            Plugins.Add(new ValidationFeature());
            containerFunq.RegisterValidators(typeof(SaveFavoriteAddressValidator).Assembly);



            SetConfig(new EndpointHostConfig
            {
                GlobalResponseHeaders =
                {
                    { "Access-Control-Allow-Origin",  "*"                               },
                    { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
                },
            });
        }
Beispiel #3
0
        public override void Configure(Container containerFunq)
        {
            Log.Info("Configure AppHost");
            new Module().Init(UnityServiceLocator.Instance);

            var container = UnityServiceLocator.Instance;

            containerFunq.Adapter = new UnityContainerAdapter(container, new Logger());

            var serverSettings = container.Resolve <IServerSettings>();

            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new CustomCredentialsAuthProvider(UnityContainerExtensions.Resolve <ICommandBus>(container),
                                                  UnityContainerExtensions.Resolve <IAccountDao>(container),
                                                  UnityContainerExtensions.Resolve <IPasswordService>(container),
                                                  UnityContainerExtensions.Resolve <IServerSettings>(container)),
                new CustomFacebookAuthProvider(UnityContainerExtensions.Resolve <IAccountDao>(container)),
                new CustomTwitterAuthProvider(UnityContainerExtensions.Resolve <IAccountDao>(container))
            }));

            Plugins.Add(new ValidationFeature());
            containerFunq.RegisterValidators(typeof(SaveFavoriteAddressValidator).Assembly);

            RequestFilters.Add((httpReq, httpResp, requestDto) =>
            {
                var authSession = httpReq.GetSession();
                if (authSession != null && !string.IsNullOrEmpty(authSession.UserAuthId))
                {
                    var account = container.Resolve <IAccountDao>().FindById(new Guid(authSession.UserAuthId));
                    if (account == null || account.DisabledByAdmin)
                    {
                        httpReq.RemoveSession();
                    }
                }
            });


            SetConfig(new EndpointHostConfig
            {
                GlobalResponseHeaders =
                {
                    { "Access-Control-Allow-Origin",  "*"                               },
                    { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
                },

                EnableFeatures = (serverSettings.ServerData.ShowAPIMetadata ? Feature.All : Feature.All.Remove(Feature.Metadata))
            });


            ContentTypeFilters.Register("text/x-csv", CsvCustomSerializer.SerializeToStream, CsvCustomSerializer.DeserializeFromStream);
            ResponseFilters.Add((req, res, dto) =>
            {
                if (req.ResponseContentType == "text/x-csv")
                {
                    res.AddHeader(HttpHeaders.ContentDisposition,
                                  string.Format("attachment;filename={0}.csv", req.OperationName));
                }
            });

            Log.Info("Configure AppHost finished");
        }
 public CacheUserRepository(IUnityContainer container)
 {
     this.Successor = ContainerExtensions.Resolve <IUserRepository>(container.Parent);
 }